brintos

brintos / llvm-project-archived public Read only

0
0
Text · 5.3 KiB · 2cc3f57 Raw
142 lines · c
1// RUN: %clang_cc1 -verify -std=c2x %s2 3// Demonstrate that we get the correct type information. Do this by leaning4// heavily on redeclarations needing to use the same type for both decls.5extern int i;6extern typeof(i) i;7extern typeof_unqual(i) i;8 9extern const int j;10extern typeof(j) j;11 12extern const int n;         // expected-note 2 {{previous declaration is here}}13extern typeof(i) n;         // expected-error {{redeclaration of 'n' with a different type: 'typeof (i)' (aka 'int') vs 'const int'}}14extern typeof_unqual(n) n;  // expected-error {{redeclaration of 'n' with a different type: 'typeof_unqual (n)' (aka 'int') vs 'const int'}}15 16// Ensure we get a redeclaration error here for the types not matching.17extern typeof(j) k;        // expected-note {{previous declaration is here}}18extern typeof_unqual(j) k; // expected-error {{redeclaration of 'k' with a different type: 'typeof_unqual (j)' (aka 'int') vs 'typeof (j)' (aka 'const int')}}19 20// Make sure the type-form of the operator also works.21extern typeof(int) l;22extern typeof_unqual(const int) l;23 24extern typeof(const int) m;        // expected-note {{previous declaration is here}}25extern typeof_unqual(const int) m; // expected-error {{redeclaration of 'm' with a different type: 'typeof_unqual(const int)' (aka 'int') vs 'typeof(const int)' (aka 'const int')}}26 27// Show that we can use an incomplete type which is then completed later.28extern typeof(struct T) *o;29struct T { int a; } t;30extern typeof(struct T) *o;31extern typeof(t) *o;32extern typeof(&t) o;33extern typeof_unqual(volatile struct T) *o;34extern typeof_unqual(t) *o;35extern typeof_unqual(&t) o;36 37// Show that we properly strip the _Atomic qualifier.38extern _Atomic int i2;39extern _Atomic(int) i2;40extern typeof(i2) i2;        // expected-note {{previous declaration is here}}41extern typeof_unqual(i2) i2; // expected-error {{redeclaration of 'i2' with a different type: 'typeof_unqual (i2)' (aka 'int') vs 'typeof (i2)' (aka '_Atomic(int)')}}42 43// We cannot take the type of a bit-field.44struct S {45  int bit : 4;46} s;47 48typeof(s.bit) nope1; // expected-error {{invalid application of 'typeof' to bit-field}}49typeof_unqual(s.bit) nope2; // expected-error {{invalid application of 'typeof_unqual' to bit-field}}50 51// Show that we properly resolve nested typeof specifiers.52extern typeof(typeof(0)) i3;53extern typeof(typeof(int)) i3;54extern typeof(typeof_unqual(0)) i3;55extern typeof(typeof_unqual(int)) i3;56extern typeof_unqual(typeof(0)) i3;57extern typeof_unqual(typeof(int)) i3;58extern typeof_unqual(typeof_unqual(0)) i3;59extern typeof_unqual(typeof_unqual(int)) i3;60extern typeof(typeof_unqual(j)) i3;61extern typeof(typeof_unqual(const int)) i3;62extern typeof_unqual(typeof(j)) i3;63extern typeof_unqual(typeof(const int)) i3;64extern typeof_unqual(typeof_unqual(j)) i3;65extern typeof_unqual(typeof_unqual(const int)) i3;66 67// Both of these result in a const int rather than an int.68extern typeof(typeof(j)) i4;69extern typeof(typeof(const int)) i4;70 71// Ensure that redundant qualifiers are allowed, same as with typedefs.72typedef const int CInt;73extern CInt i4;74extern const CInt i4;75extern const typeof(j) i4;76extern const typeof(const int) i4;77extern const typeof(CInt) i4;78 79// Qualifiers are not redundant here, but validating that the qualifiers are80// still honored.81extern const typeof_unqual(j) i4;82extern const typeof_unqual(const int) i4;83extern const typeof_unqual(CInt) i4;84 85// Show that type attributes are stripped from the unqualified version.86extern __attribute__((address_space(0))) int type_attr_test_2_obj;87extern int type_attr_test_2;88extern typeof_unqual(type_attr_test_2_obj) type_attr_test_2;            // expected-note {{previous declaration is here}}89extern __attribute__((address_space(0))) int type_attr_test_2;          // expected-error {{redeclaration of 'type_attr_test_2' with a different type: '__attribute__((address_space(0))) int' vs 'typeof_unqual (type_attr_test_2_obj)' (aka 'int')}}90 91// Ensure that an invalid type doesn't cause crashes.92void invalid_param_fn(__attribute__((address_space(1))) int i); // expected-error {{parameter may not be qualified with an address space}}93typeof(invalid_param_fn) invalid_param_1;94typeof_unqual(invalid_param_fn) invalid_param_2;95 96// Ensure restrict is stripped97extern int *restrict p1;98extern int *p2;99extern typeof(p1) p1;100extern typeof_unqual(p1) p2;101 102// Ensure array qualifications are removed103extern const int aci[2];104extern const int acii[2][2];105extern int ai[2];106extern int aii[2][2];107extern typeof(aci) aci;108extern typeof_unqual(aci) ai;109extern typeof(acii) acii;110extern typeof_unqual(acii) aii;111 112extern int *restrict arpi[2];113extern int *restrict arpii[2][2];114extern int *api[2];115extern int *apii[2][2];116extern typeof(arpi) arpi;117extern typeof_unqual(arpi) api;118extern typeof(arpii) arpii;119extern typeof_unqual(arpii) apii;120 121extern int _Atomic aAi[2];122extern int _Atomic aAii[2][2];123extern typeof(aAi) aAi;124extern typeof_unqual(aAi) aAi;125extern typeof(aAii) aAii;126extern typeof_unqual(aAii) aAii;127 128extern _Atomic(int) aAi[2];129extern _Atomic(int) aAii[2][2];130extern typeof(aAi) aAi;131extern typeof_unqual(aAi) aAi;132extern typeof(aAii) aAii;133extern typeof_unqual(aAii) aAii;134 135const char* const animals[] = { "aardvark", "bluejay", "catte" };136void GH92667(void) {137 const char* animals2_array1[3];138 typeof_unqual(animals) animals2_array;139 animals2_array1[0] = 0;140 animals2_array[0] = 0;141}142