1// REQUIRES: xcore-registered-target
2// RUN: %clang_cc1 -triple xcore-unknown-unknown -fno-signed-char -fno-common -emit-llvm -o - %s | FileCheck %s
3
4// CHECK: target triple = "xcore-unknown-unknown"
5
6// In the tests below, some types are not supported by the ABI (_Complex,
7// variable length arrays) and will thus emit no meta data.
8// The 33 tests that do emit typestrings are gathered into '!xcore.typestrings'
9// Please see 'Tools Development Guide' section 2.16.2 for format details:
10// <https://www.xmos.com/download/public/Tools-Development-Guide%28X9114A%29.pdf>
11
12// CHECK: !xcore.typestrings = !{!1, !2, !3, !4, !5, !6, !7, !8, !9, !10, !11,
13// CHECK: !12, !13, !14, !15, !16, !17, !18, !19, !20, !21, !22, !23, !24, !25,
14// CHECK: !26, !27, !28, !29, !30, !31, !32, !33, !34, !35, !36, !37, !38}
15
16
17// test BuiltinType
18// CHECK: !1 = metadata !{void (i1, i8, i8, i8, i16, i16, i16, i32, i32, i32,
19// CHECK:      i32, i32, i32, i64, i64, i64, float, double, double)*
20// CHECK:      @builtinType, metadata !"f{0}(b,uc,uc,sc,ss,us,ss,si,ui,si,sl,
21// CHECK:      ul,sl,sll,ull,sll,ft,d,ld)"}
22void builtinType(_Bool B, char C, unsigned char UC, signed char SC, short S,
23                 unsigned short US, signed short SS, int I, unsigned int UI,
24                 signed int SI, long L, unsigned long UL, signed long SL,
25                 long long LL, unsigned long long ULL, signed long long SLL,
26                 float F, double D, long double LD) {}
27double _Complex Complex; // not supported
28
29
30// test FunctionType & Qualifiers
31// CHECK: !2 = metadata !{void ()* @gI, metadata !"f{0}()"}
32// CHECK: !3 = metadata !{void (...)* @eI, metadata !"f{0}()"}
33// CHECK: !4 = metadata !{void ()* @gV, metadata !"f{0}(0)"}
34// CHECK: !5 = metadata !{void ()* @eV, metadata !"f{0}(0)"}
35// CHECK: !6 = metadata !{void (i32, ...)* @gVA, metadata !"f{0}(si,va)"}
36// CHECK: !7 = metadata !{void (i32, ...)* @eVA, metadata !"f{0}(si,va)"}
37// CHECK: !8 = metadata !{i32* (i32*)* @gQ, metadata !"f{crv:p(cv:si)}(p(cv:si))"}
38// CHECK: !9 = metadata !{i32* (i32*)* @eQ, metadata !"f{crv:p(cv:si)}(p(cv:si))"}
39extern void eI();
40void gI() {eI();};
41extern void eV(void);
42void gV(void) {eV();}
43extern void eVA(int, ...);
44void gVA(int i, ...) {eVA(i);}
45extern const volatile int* volatile restrict const
46    eQ(const volatile int * volatile restrict const);
47const volatile int* volatile restrict const
48    gQ(const volatile int * volatile restrict const i) {return eQ(i);}
49
50
51// test PointerType
52// CHECK: !10 = metadata !{i32* (i32*, i32* (i32*)*)*
53// CHECK:       @pointerType, metadata !"f{p(si)}(p(si),p(f{p(si)}(p(si))))"}
54// CHECK: !11 = metadata !{i32** @EP, metadata !"p(si)"}
55// CHECK: !12 = metadata !{i32** @GP, metadata !"p(si)"}
56extern int* EP;
57int* GP;
58int* pointerType(int *I, int * (*FP)(int *)) {
59  return I? EP : GP;
60}
61
62// test ArrayType
63// CHECK: !13 = metadata !{[2 x i32]* (i32*, i32*, [2 x i32]*, [2 x i32]*, i32*)*
64// CHECK:       @arrayType, metadata !"f{p(a(2:si))}(p(si),p(cv:si),p(a(2:si)),
65// CHECK:       p(a(2:si)),p(si))"}
66// CHECK: !14 = metadata !{[0 x i32]* @EA1, metadata !"a(*:cv:si)"}
67// CHECK: !15 = metadata !{[2 x i32]* @EA2, metadata !"a(2:si)"}
68// CHECK: !16 = metadata !{[0 x [2 x i32]]* @EA3, metadata !"a(*:a(2:si))"}
69// CHECK: !17 = metadata !{[3 x [2 x i32]]* @EA4, metadata !"a(3:a(2:si))"}
70// CHECK: !18 = metadata !{[2 x i32]* @GA1, metadata !"a(2:cv:si)"}
71// CHECK: !19 = metadata !{void ([2 x i32]*)* @arrayTypeVariable1,
72// CHECK:       metadata !"f{0}(p(a(2:si)))"}
73// CHECK: !20 = metadata !{void (void ([2 x i32]*)*)* @arrayTypeVariable2,
74// CHECK:       metadata !"f{0}(p(f{0}(p(a(2:si)))))"}
75// CHECK: !21 = metadata !{[3 x [2 x i32]]* @GA2, metadata !"a(3:a(2:si))"}
76extern int GA2[3][2];
77extern const volatile int EA1[];
78extern int EA2[2];
79extern int EA3[][2];
80extern int EA4[3][2];
81const volatile int GA1[2];
82extern void arrayTypeVariable1(int[*][2]);
83extern void arrayTypeVariable2( void(*fp)(int[*][2]) );
84extern void arrayTypeVariable3(int[3][*]);                // not supported
85extern void arrayTypeVariable4( void(*fp)(int[3][*]) );   // not supported
86typedef int RetType[2];
87RetType* arrayType(int A1[], int const volatile A2[2], int A3[][2],
88                   int A4[3][2], int A5[const volatile restrict static 2]) {
89  if (A1) EA2[0] = EA1[0];
90  if (A2) return &EA2;
91  if (A3) return EA3;
92  if (A4) return EA4;
93  if (A5) EA2[0] = GA1[0];
94  arrayTypeVariable1(EA4);
95  arrayTypeVariable2(arrayTypeVariable1);
96  arrayTypeVariable3(EA4);
97  arrayTypeVariable4(arrayTypeVariable3);
98  return GA2;
99}
100
101
102// test StructureType
103// CHECK: !22 = metadata !{void (%struct.S1*)* @structureType1, metadata
104// CHECK:       !"f{0}(s(S1){m(ps2){p(s(S2){m(ps3){p(s(S3){m(s1){s(S1){}}})}})}})"}
105// CHECK: !23 = metadata !{void (%struct.S2*)* @structureType2, metadata
106// CHECK:       !"f{0}(s(S2){m(ps3){p(s(S3){m(s1){s(S1){m(ps2){p(s(S2){})}}}})}})"}
107// CHECK: !24 = metadata !{void (%struct.S3*)* @structureType3, metadata
108// CHECK:       !"f{0}(s(S3){m(s1){s(S1){m(ps2){p(s(S2){m(ps3){p(s(S3){})}})}}}})"}
109// CHECK: !25 = metadata !{void (%struct.S4*)* @structureType4, metadata
110// CHECK:       !"f{0}(s(S4){m(s1){s(S1){m(ps2){p(s(S2){m(ps3){p(s(S3){m(s1){s(S1){}}})}})}}}})"}
111// CHECK: !26 = metadata !{%struct.anon* @StructAnon, metadata !"s(){m(A){si}}"}
112// CHECK: !27 = metadata !{i32 (%struct.SB*)* @structureTypeB, metadata
113// CHECK:       !"f{si}(s(SB){m(){b(4:si)},m(){b(2:si)},m(N4){b(4:si)},
114// CHECK:       m(N2){b(2:si)},m(){b(4:ui)},m(){b(4:si)},m(){b(4:c:si)},
115// CHECK:       m(){b(4:c:si)},m(){b(4:cv:si)}})"}
116struct S2;
117struct S1{struct S2 *ps2;};
118struct S3;
119struct S2{struct S3 *ps3;};
120struct S3{struct S1 s1;};
121struct S4{struct S1 s1;};
122void structureType1(struct S1 s1){}
123void structureType2(struct S2 s2){}
124void structureType3(struct S3 s3){}
125void structureType4(struct S4 s4){}
126struct {int A;} StructAnon = {1};
127struct SB{int:4; int:2; int N4:4; int N2:2; unsigned int:4; signed int:4;
128          const int:4; int const :4; volatile const int:4;};
129int structureTypeB(struct SB sb){return StructAnon.A;}
130
131
132// test UnionType
133// CHECK: !28 = metadata !{void (%union.U1*)* @unionType1, metadata
134// CHECK:       !"f{0}(u(U1){m(pu2){p(u(U2){m(pu3){p(u(U3){m(u1){u(U1){}}})}})}})"}
135// CHECK: !29 = metadata !{void (%union.U2*)* @unionType2, metadata
136// CHECK:       !"f{0}(u(U2){m(pu3){p(u(U3){m(u1){u(U1){m(pu2){p(u(U2){})}}}})}})"}
137// CHECK: !30 = metadata !{void (%union.U3*)* @unionType3, metadata
138// CHECK:       !"f{0}(u(U3){m(u1){u(U1){m(pu2){p(u(U2){m(pu3){p(u(U3){})}})}}}})"}
139// CHECK: !31 = metadata !{void (%union.U4*)* @unionType4, metadata
140// CHECK:       !"f{0}(u(U4){m(u1){u(U1){m(pu2){p(u(U2){m(pu3){p(u(U3){m(u1){u(U1){}}})}})}}}})"}
141// CHECK: !32 = metadata !{%union.anon* @UnionAnon, metadata !"u(){m(A){si}}"}
142// CHECK: !33 = metadata !{i32 (%union.UB*)* @unionTypeB, metadata
143// CHECK:       !"f{si}(u(UB){m(N2){b(2:si)},m(N4){b(4:si)},m(){b(2:si)},
144// CHECK:       m(){b(4:c:si)},m(){b(4:c:si)},m(){b(4:cv:si)},m(){b(4:si)},
145// CHECK:       m(){b(4:si)},m(){b(4:ui)}})"}
146union U2;
147union U1{union U2 *pu2;};
148union U3;
149union U2{union U3 *pu3;};
150union U3{union U1 u1;};
151union U4{union U1 u1;};
152void unionType1(union U1 u1) {}
153void unionType2(union U2 u2) {}
154void unionType3(union U3 u3) {}
155void unionType4(union U4 u4) {}
156union UB{int:4; int:2; int N4:4; int N2:2; unsigned int:4; signed int:4;
157         const int:4; int const :4; volatile const int:4;};
158union {int A;} UnionAnon = {1};
159int unionTypeB(union UB ub) {return UnionAnon.A;}
160
161
162// test EnumType
163// CHECK: !34 = metadata !{i32* @EnumAnon, metadata !"e(){m(EA){3}}"}
164// CHECK: !35 = metadata !{i32 (i32)* @enumType, metadata
165// CHECK:       !"f{si}(e(E){m(A){7},m(B){6},m(C){5},m(D){0}})"}
166enum E {D, C=5, B, A};
167enum {EA=3} EnumAnon = EA;
168int enumType(enum E e) {return EnumAnon;}
169
170
171// CHECK: !36 = metadata !{i32 ()* @testReDecl, metadata !"f{si}()"}
172// CHECK: !37 = metadata !{[10 x i32]* @After, metadata !"a(10:si)"}
173// CHECK: !38 = metadata !{[10 x i32]* @Before, metadata !"a(10:si)"}
174extern int After[];
175extern int Before[10];
176int testReDecl() {return After[0] + Before[0];}
177int After[10];
178int Before[];
179
180