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