1 // RUN: %clang_cc1 -triple x86_64-unknown-nacl -emit-llvm -o - %s| FileCheck %s
2 #include <stdarg.h>
3 // Test for x86-64 structure representation (instead of pnacl representation),
4 // in particular for unions. Also crib a few tests from x86 Linux.
5 
6 union PP_VarValue {
7   int as_int;
8   double as_double;
9   long long as_i64;
10 };
11 
12 struct PP_Var {
13   int type;
14   int padding;
15   union PP_VarValue value;
16 };
17 
18 // CHECK: define{{.*}} { i64, i64 } @f0()
f0()19 struct PP_Var f0() {
20   struct PP_Var result = { 0, 0, 0 };
21   return result;
22 }
23 
24 // CHECK-LABEL: define{{.*}} void @f1(i64 %p1.coerce0, i64 %p1.coerce1)
f1(struct PP_Var p1)25 void f1(struct PP_Var p1) { while(1) {} }
26 
27 // long doubles are 64 bits on NaCl
28 // CHECK-LABEL: define{{.*}} double @f5()
f5(void)29 long double f5(void) {
30   return 0;
31 }
32 
33 // CHECK-LABEL: define{{.*}} void @f6(i8 signext %a0, i16 signext %a1, i32 %a2, i64 %a3, i8* %a4)
f6(char a0,short a1,int a2,long long a3,void * a4)34 void f6(char a0, short a1, int a2, long long a3, void *a4) {
35 }
36 
37 // CHECK-LABEL: define{{.*}} i64 @f8_1()
38 // CHECK-LABEL: define{{.*}} void @f8_2(i64 %a0.coerce)
39 union u8 {
40   long double a;
41   int b;
42 };
f8_1()43 union u8 f8_1() { while (1) {} }
f8_2(union u8 a0)44 void f8_2(union u8 a0) {}
45 
46 // CHECK-LABEL: define{{.*}} i64 @f9()
f9(void)47 struct s9 { int a; int b; int : 0; } f9(void) { while (1) {} }
48 
49 // CHECK-LABEL: define{{.*}} void @f10(i64 %a0.coerce)
50 struct s10 { int a; int b; int : 0; };
f10(struct s10 a0)51 void f10(struct s10 a0) {}
52 
53 // CHECK-LABEL: define{{.*}} double @f11()
f11()54 union { long double a; float b; } f11() { while (1) {} }
55 
56 // CHECK-LABEL: define{{.*}} i32 @f12_0()
57 // CHECK-LABEL: define{{.*}} void @f12_1(i32 %a0.coerce)
58 struct s12 { int a __attribute__((aligned(16))); };
f12_0(void)59 struct s12 f12_0(void) { while (1) {} }
f12_1(struct s12 a0)60 void f12_1(struct s12 a0) {}
61 
62 // Check that sret parameter is accounted for when checking available integer
63 // registers.
64 // CHECK: define{{.*}} void @f13(%struct.s13_0* noalias sret(%struct.s13_0) align 8 %agg.result, i32 %a, i32 %b, i32 %c, i32 %d, {{.*}}* byval({{.*}}) align 8 %e, i32 %f)
65 
66 struct s13_0 { long long f0[3]; };
67 struct s13_1 { long long f0[2]; };
f13(int a,int b,int c,int d,struct s13_1 e,int f)68 struct s13_0 f13(int a, int b, int c, int d,
69                  struct s13_1 e, int f) { while (1) {} }
70 
71 // CHECK-LABEL: define{{.*}} void @f20(%struct.s20* byval(%struct.s20) align 32 %x)
72 struct __attribute__((aligned(32))) s20 {
73   int x;
74   int y;
75 };
f20(struct s20 x)76 void f20(struct s20 x) {}
77 
78 
79 // CHECK: declare void @func(i64)
80 typedef struct _str {
81   union {
82     long double a;
83     long c;
84   };
85 } str;
86 
87 void func(str s);
88 str ss;
f9122143()89 void f9122143()
90 {
91   func(ss);
92 }
93