xref: /minix3/external/bsd/llvm/dist/clang/test/CodeGen/x86_64-arguments-nacl.c (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -triple x86_64-unknown-nacl -emit-llvm -o - %s| FileCheck %s
2*f4a2713aSLionel Sambuc #include <stdarg.h>
3*f4a2713aSLionel Sambuc // Test for x86-64 structure representation (instead of pnacl representation),
4*f4a2713aSLionel Sambuc // in particular for unions. Also crib a few tests from x86 Linux.
5*f4a2713aSLionel Sambuc 
6*f4a2713aSLionel Sambuc union PP_VarValue {
7*f4a2713aSLionel Sambuc   int as_int;
8*f4a2713aSLionel Sambuc   double as_double;
9*f4a2713aSLionel Sambuc   long long as_i64;
10*f4a2713aSLionel Sambuc };
11*f4a2713aSLionel Sambuc 
12*f4a2713aSLionel Sambuc struct PP_Var {
13*f4a2713aSLionel Sambuc   int type;
14*f4a2713aSLionel Sambuc   int padding;
15*f4a2713aSLionel Sambuc   union PP_VarValue value;
16*f4a2713aSLionel Sambuc };
17*f4a2713aSLionel Sambuc 
18*f4a2713aSLionel Sambuc // CHECK: define { i64, i64 } @f0()
f0()19*f4a2713aSLionel Sambuc struct PP_Var f0() {
20*f4a2713aSLionel Sambuc   struct PP_Var result = { 0, 0, 0 };
21*f4a2713aSLionel Sambuc   return result;
22*f4a2713aSLionel Sambuc }
23*f4a2713aSLionel Sambuc 
24*f4a2713aSLionel Sambuc // CHECK-LABEL: define void @f1(i64 %p1.coerce0, i64 %p1.coerce1)
f1(struct PP_Var p1)25*f4a2713aSLionel Sambuc void f1(struct PP_Var p1) { while(1) {} }
26*f4a2713aSLionel Sambuc 
27*f4a2713aSLionel Sambuc // long doubles are 64 bits on NaCl
28*f4a2713aSLionel Sambuc // CHECK-LABEL: define double @f5()
f5(void)29*f4a2713aSLionel Sambuc long double f5(void) {
30*f4a2713aSLionel Sambuc   return 0;
31*f4a2713aSLionel Sambuc }
32*f4a2713aSLionel Sambuc 
33*f4a2713aSLionel Sambuc // 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*f4a2713aSLionel Sambuc void f6(char a0, short a1, int a2, long long a3, void *a4) {
35*f4a2713aSLionel Sambuc }
36*f4a2713aSLionel Sambuc 
37*f4a2713aSLionel Sambuc // CHECK-LABEL: define i64 @f8_1()
38*f4a2713aSLionel Sambuc // CHECK-LABEL: define void @f8_2(i64 %a0.coerce)
39*f4a2713aSLionel Sambuc union u8 {
40*f4a2713aSLionel Sambuc   long double a;
41*f4a2713aSLionel Sambuc   int b;
42*f4a2713aSLionel Sambuc };
f8_1()43*f4a2713aSLionel Sambuc union u8 f8_1() { while (1) {} }
f8_2(union u8 a0)44*f4a2713aSLionel Sambuc void f8_2(union u8 a0) {}
45*f4a2713aSLionel Sambuc 
46*f4a2713aSLionel Sambuc // CHECK-LABEL: define i64 @f9()
f9(void)47*f4a2713aSLionel Sambuc struct s9 { int a; int b; int : 0; } f9(void) { while (1) {} }
48*f4a2713aSLionel Sambuc 
49*f4a2713aSLionel Sambuc // CHECK-LABEL: define void @f10(i64 %a0.coerce)
50*f4a2713aSLionel Sambuc struct s10 { int a; int b; int : 0; };
f10(struct s10 a0)51*f4a2713aSLionel Sambuc void f10(struct s10 a0) {}
52*f4a2713aSLionel Sambuc 
53*f4a2713aSLionel Sambuc // CHECK-LABEL: define double @f11()
f11()54*f4a2713aSLionel Sambuc union { long double a; float b; } f11() { while (1) {} }
55*f4a2713aSLionel Sambuc 
56*f4a2713aSLionel Sambuc // CHECK-LABEL: define i32 @f12_0()
57*f4a2713aSLionel Sambuc // CHECK-LABEL: define void @f12_1(i32 %a0.coerce)
58*f4a2713aSLionel Sambuc struct s12 { int a __attribute__((aligned(16))); };
f12_0(void)59*f4a2713aSLionel Sambuc struct s12 f12_0(void) { while (1) {} }
f12_1(struct s12 a0)60*f4a2713aSLionel Sambuc void f12_1(struct s12 a0) {}
61*f4a2713aSLionel Sambuc 
62*f4a2713aSLionel Sambuc // Check that sret parameter is accounted for when checking available integer
63*f4a2713aSLionel Sambuc // registers.
64*f4a2713aSLionel Sambuc // CHECK: define void @f13(%struct.s13_0* noalias sret %agg.result, i32 %a, i32 %b, i32 %c, i32 %d, {{.*}}* byval align 8 %e, i32 %f)
65*f4a2713aSLionel Sambuc 
66*f4a2713aSLionel Sambuc struct s13_0 { long long f0[3]; };
67*f4a2713aSLionel Sambuc struct s13_1 { long long f0[2]; };
f13(int a,int b,int c,int d,struct s13_1 e,int f)68*f4a2713aSLionel Sambuc struct s13_0 f13(int a, int b, int c, int d,
69*f4a2713aSLionel Sambuc                  struct s13_1 e, int f) { while (1) {} }
70*f4a2713aSLionel Sambuc 
71*f4a2713aSLionel Sambuc // CHECK-LABEL: define void @f20(%struct.s20* byval align 32 %x)
72*f4a2713aSLionel Sambuc struct __attribute__((aligned(32))) s20 {
73*f4a2713aSLionel Sambuc   int x;
74*f4a2713aSLionel Sambuc   int y;
75*f4a2713aSLionel Sambuc };
f20(struct s20 x)76*f4a2713aSLionel Sambuc void f20(struct s20 x) {}
77*f4a2713aSLionel Sambuc 
78*f4a2713aSLionel Sambuc 
79*f4a2713aSLionel Sambuc // CHECK: declare void @func(i64)
80*f4a2713aSLionel Sambuc typedef struct _str {
81*f4a2713aSLionel Sambuc   union {
82*f4a2713aSLionel Sambuc     long double a;
83*f4a2713aSLionel Sambuc     long c;
84*f4a2713aSLionel Sambuc   };
85*f4a2713aSLionel Sambuc } str;
86*f4a2713aSLionel Sambuc 
87*f4a2713aSLionel Sambuc void func(str s);
88*f4a2713aSLionel Sambuc str ss;
f9122143()89*f4a2713aSLionel Sambuc void f9122143()
90*f4a2713aSLionel Sambuc {
91*f4a2713aSLionel Sambuc   func(ss);
92*f4a2713aSLionel Sambuc }
93*f4a2713aSLionel Sambuc 
94*f4a2713aSLionel Sambuc 
95*f4a2713aSLionel Sambuc typedef struct {
96*f4a2713aSLionel Sambuc   int a;
97*f4a2713aSLionel Sambuc   int b;
98*f4a2713aSLionel Sambuc } s1;
99*f4a2713aSLionel Sambuc // CHECK-LABEL: define i32 @f48(%struct.s1* byval %s)
f48(s1 s)100*f4a2713aSLionel Sambuc int __attribute__((pnaclcall)) f48(s1 s) { return s.a; }
101*f4a2713aSLionel Sambuc 
102*f4a2713aSLionel Sambuc // CHECK-LABEL: define void @f49(%struct.s1* noalias sret %agg.result)
f49()103*f4a2713aSLionel Sambuc s1 __attribute__((pnaclcall)) f49() { s1 s; s.a = s.b = 1; return s; }
104*f4a2713aSLionel Sambuc 
105*f4a2713aSLionel Sambuc union simple_union {
106*f4a2713aSLionel Sambuc   int a;
107*f4a2713aSLionel Sambuc   char b;
108*f4a2713aSLionel Sambuc };
109*f4a2713aSLionel Sambuc // Unions should be passed as byval structs
110*f4a2713aSLionel Sambuc // CHECK-LABEL: define void @f50(%union.simple_union* byval %s)
f50(union simple_union s)111*f4a2713aSLionel Sambuc void __attribute__((pnaclcall)) f50(union simple_union s) {}
112*f4a2713aSLionel Sambuc 
113*f4a2713aSLionel Sambuc typedef struct {
114*f4a2713aSLionel Sambuc   int b4 : 4;
115*f4a2713aSLionel Sambuc   int b3 : 3;
116*f4a2713aSLionel Sambuc   int b8 : 8;
117*f4a2713aSLionel Sambuc } bitfield1;
118*f4a2713aSLionel Sambuc // Bitfields should be passed as byval structs
119*f4a2713aSLionel Sambuc // CHECK-LABEL: define void @f51(%struct.bitfield1* byval %bf1)
f51(bitfield1 bf1)120*f4a2713aSLionel Sambuc void __attribute__((pnaclcall)) f51(bitfield1 bf1) {}
121