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