xref: /llvm-project/clang/test/Sema/types.c (revision 3ab94b910bec14e4055a44eb4c652000589ea028)
1 // RUN: %clang_cc1 %s -pedantic -verify -triple=x86_64-apple-darwin9
2 // RUN: %clang_cc1 %s -pedantic -verify -triple=mips64-linux-gnu
3 
4 // rdar://6097662
5 typedef int (*T)[2];
6 restrict T x;
7 
8 typedef int *S[2];
9 restrict S y; // expected-error {{restrict requires a pointer or reference ('S' (aka 'int *[2]') is invalid)}}
10 
11 
12 
13 // int128_t is available.
14 int a() {
15   __int128_t s;
16   __uint128_t t;
17 }
18 // but not a keyword
19 int b() {
20   int __int128_t;
21   int __uint128_t;
22 }
23 // __int128 is a keyword
24 int c() {
25   __int128 i;
26   unsigned __int128 j;
27   long unsigned __int128 k; // expected-error {{'long __int128' is invalid}}
28   int __int128; // expected-error {{cannot combine with previous}} expected-warning {{does not declare anything}}
29 }
30 // __int128_t is __int128; __uint128_t is unsigned __int128.
31 typedef __int128 check_int_128; // expected-note {{here}}
32 typedef __int128_t check_int_128; // expected-note {{here}} expected-warning {{redefinition}}
33 typedef int check_int_128; // expected-error {{different types ('int' vs '__int128_t' (aka '__int128'))}}
34 
35 typedef unsigned __int128 check_uint_128; // expected-note {{here}}
36 typedef __uint128_t check_uint_128; // expected-note {{here}} expected-warning {{redefinition}}
37 typedef int check_uint_128; // expected-error {{different types ('int' vs '__uint128_t' (aka 'unsigned __int128'))}}
38 
39 // Array type merging should convert array size to whatever matches the target
40 // pointer size.
41 // rdar://6880874
42 extern int i[1LL];
43 int i[(short)1];
44 
45 enum e { e_1 };
46 extern int j[sizeof(enum e)];  // expected-note {{previous definition}}
47 int j[42];   // expected-error {{redefinition of 'j' with a different type: 'int [42]' vs 'int [4]'}}
48 
49 // rdar://6880104
50 _Decimal32 x;  // expected-error {{GNU decimal type extension not supported}}
51 
52 
53 // rdar://6880951
54 int __attribute__ ((vector_size (8), vector_size (8))) v;  // expected-error {{invalid vector element type}}
55 
56 void test(int i) {
57   char c = (char __attribute__((aligned(8)))) i; // expected-warning {{'aligned' attribute ignored when parsing type}}
58 }
59 
60 // http://llvm.org/PR11082
61 //
62 // FIXME: This may or may not be the correct approach (no warning or error),
63 // but large amounts of Linux and FreeBSD code need this attribute to not be
64 // a hard error in order to work correctly.
65 void test2(int i) {
66   char c = (char __attribute__((may_alias))) i;
67 }
68 
69 // vector size too large
70 int __attribute__ ((vector_size(8192))) x1; // expected-error {{vector size too large}}
71 typedef int __attribute__ ((ext_vector_type(8192))) x2; // expected-error {{vector size too large}}
72 
73 // no support for vector enum type
74 enum { e_2 } x3 __attribute__((vector_size(64))); // expected-error {{invalid vector element type}}
75 
76 int x4 __attribute__((ext_vector_type(64)));  // expected-error {{'ext_vector_type' attribute only applies to types}}
77 
78 // rdar://16492792
79 typedef __attribute__ ((ext_vector_type(32),__aligned__(32))) unsigned char uchar32;
80 
81 void convert() {
82     uchar32 r = 0;
83     r.s[ 1234 ] = 1; // expected-error {{illegal vector component name 's'}}
84 }
85