blob: cbfad1a1cb572059ebd63d5a764a96b1e60c6606 [file] [log] [blame]
Derek Schuff7da46f92012-10-11 16:55:58 +00001// 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
6union PP_VarValue {
7 int as_int;
8 double as_double;
9 long long as_i64;
10};
11
12struct PP_Var {
13 int type;
14 int padding;
15 union PP_VarValue value;
16};
17
18// CHECK: define { i64, i64 } @f0()
19struct PP_Var f0() {
20 struct PP_Var result = { 0, 0, 0 };
21 return result;
22}
23
Stephen Lin93ab6bf2013-08-15 06:47:53 +000024// CHECK-LABEL: define void @f1(i64 %p1.coerce0, i64 %p1.coerce1)
Derek Schuff7da46f92012-10-11 16:55:58 +000025void f1(struct PP_Var p1) { while(1) {} }
26
27// long doubles are 64 bits on NaCl
Stephen Lin93ab6bf2013-08-15 06:47:53 +000028// CHECK-LABEL: define double @f5()
Derek Schuff7da46f92012-10-11 16:55:58 +000029long double f5(void) {
30 return 0;
31}
32
Stephen Lin93ab6bf2013-08-15 06:47:53 +000033// CHECK-LABEL: define void @f6(i8 signext %a0, i16 signext %a1, i32 %a2, i64 %a3, i8* %a4)
Derek Schuff7da46f92012-10-11 16:55:58 +000034void f6(char a0, short a1, int a2, long long a3, void *a4) {
35}
36
Stephen Lin93ab6bf2013-08-15 06:47:53 +000037// CHECK-LABEL: define i64 @f8_1()
38// CHECK-LABEL: define void @f8_2(i64 %a0.coerce)
Derek Schuff7da46f92012-10-11 16:55:58 +000039union u8 {
40 long double a;
41 int b;
42};
43union u8 f8_1() { while (1) {} }
44void f8_2(union u8 a0) {}
45
Stephen Lin93ab6bf2013-08-15 06:47:53 +000046// CHECK-LABEL: define i64 @f9()
Derek Schuff7da46f92012-10-11 16:55:58 +000047struct s9 { int a; int b; int : 0; } f9(void) { while (1) {} }
48
Stephen Lin93ab6bf2013-08-15 06:47:53 +000049// CHECK-LABEL: define void @f10(i64 %a0.coerce)
Derek Schuff7da46f92012-10-11 16:55:58 +000050struct s10 { int a; int b; int : 0; };
51void f10(struct s10 a0) {}
52
Stephen Lin93ab6bf2013-08-15 06:47:53 +000053// CHECK-LABEL: define double @f11()
Derek Schuff7da46f92012-10-11 16:55:58 +000054union { long double a; float b; } f11() { while (1) {} }
55
Stephen Lin93ab6bf2013-08-15 06:47:53 +000056// CHECK-LABEL: define i32 @f12_0()
57// CHECK-LABEL: define void @f12_1(i32 %a0.coerce)
Derek Schuff7da46f92012-10-11 16:55:58 +000058struct s12 { int a __attribute__((aligned(16))); };
59struct s12 f12_0(void) { while (1) {} }
60void f12_1(struct s12 a0) {}
61
62// Check that sret parameter is accounted for when checking available integer
63// registers.
Bill Wendlingc1ea4b92013-02-15 05:25:49 +000064// 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)
Derek Schuff7da46f92012-10-11 16:55:58 +000065
66struct s13_0 { long long f0[3]; };
67struct s13_1 { long long f0[2]; };
68struct s13_0 f13(int a, int b, int c, int d,
69 struct s13_1 e, int f) { while (1) {} }
70
Stephen Lin93ab6bf2013-08-15 06:47:53 +000071// CHECK-LABEL: define void @f20(%struct.s20* byval align 32 %x)
Derek Schuff7da46f92012-10-11 16:55:58 +000072struct __attribute__((aligned(32))) s20 {
73 int x;
74 int y;
75};
76void f20(struct s20 x) {}
77
78
79// CHECK: declare void @func(i64)
80typedef struct _str {
81 union {
82 long double a;
83 long c;
84 };
85} str;
86
87void func(str s);
88str ss;
89void f9122143()
90{
91 func(ss);
92}