1*67e74705SXin Li // RUN: %clang_cc1 %s -triple=renderscript32-none-linux-gnueabi -emit-llvm -o - -Werror | FileCheck %s -check-prefix=CHECK-RS32
2*67e74705SXin Li // RUN: %clang_cc1 %s -triple=renderscript64-none-linux-android -emit-llvm -o - -Werror | FileCheck %s -check-prefix=CHECK-RS64
3*67e74705SXin Li // RUN: %clang_cc1 %s -triple=armv7-none-linux-gnueabi -emit-llvm -o - -Werror | FileCheck %s -check-prefix=CHECK-ARM
4*67e74705SXin Li
5*67e74705SXin Li // Ensure that the bitcode has the correct triple
6*67e74705SXin Li // CHECK-RS32: target triple = "armv7-none-linux-gnueabi"
7*67e74705SXin Li // CHECK-RS64: target triple = "aarch64-none-linux-android"
8*67e74705SXin Li // CHECK-ARM: target triple = "armv7-none-linux-gnueabi"
9*67e74705SXin Li
10*67e74705SXin Li // Ensure that long data type has 8-byte size and alignment in RenderScript
11*67e74705SXin Li #ifdef __RENDERSCRIPT__
12*67e74705SXin Li #define LONG_WIDTH_AND_ALIGN 8
13*67e74705SXin Li #else
14*67e74705SXin Li #define LONG_WIDTH_AND_ALIGN 4
15*67e74705SXin Li #endif
16*67e74705SXin Li
17*67e74705SXin Li _Static_assert(sizeof(long) == LONG_WIDTH_AND_ALIGN, "sizeof long is wrong");
18*67e74705SXin Li _Static_assert(_Alignof(long) == LONG_WIDTH_AND_ALIGN, "sizeof long is wrong");
19*67e74705SXin Li
20*67e74705SXin Li // CHECK-RS32: i64 @test_long(i64 %v)
21*67e74705SXin Li // CHECK-RS64: i64 @test_long(i64 %v)
22*67e74705SXin Li // CHECK-ARM: i32 @test_long(i32 %v)
test_long(long v)23*67e74705SXin Li long test_long(long v) {
24*67e74705SXin Li return v + 1;
25*67e74705SXin Li }
26*67e74705SXin Li
27*67e74705SXin Li // =============================================================================
28*67e74705SXin Li // Test coercion of aggregate argument or return value into integer arrays
29*67e74705SXin Li // =============================================================================
30*67e74705SXin Li
31*67e74705SXin Li // =============================================================================
32*67e74705SXin Li // aggregate parameter <= 4 bytes: coerced to [a x iNN] for both 32-bit and
33*67e74705SXin Li // 64-bit RenderScript
34*67e74705SXin Li // ==============================================================================
35*67e74705SXin Li
36*67e74705SXin Li typedef struct {char c1, c2, c3; } sChar3;
37*67e74705SXin Li typedef struct {short s; char c;} sShortChar;
38*67e74705SXin Li
39*67e74705SXin Li // CHECK-RS32: void @argChar3([3 x i8] %s.coerce)
40*67e74705SXin Li // CHECK-RS64: void @argChar3([3 x i8] %s.coerce)
argChar3(sChar3 s)41*67e74705SXin Li void argChar3(sChar3 s) {}
42*67e74705SXin Li
43*67e74705SXin Li // CHECK-RS32: void @argShortChar([2 x i16] %s.coerce)
44*67e74705SXin Li // CHECK-RS64: void @argShortChar([2 x i16] %s.coerce)
argShortChar(sShortChar s)45*67e74705SXin Li void argShortChar(sShortChar s) {}
46*67e74705SXin Li
47*67e74705SXin Li // =============================================================================
48*67e74705SXin Li // aggregate return value <= 4 bytes: coerced to [a x iNN] for both 32-bit and
49*67e74705SXin Li // 64-bit RenderScript
50*67e74705SXin Li // =============================================================================
51*67e74705SXin Li
52*67e74705SXin Li // CHECK-RS32: [3 x i8] @retChar3()
53*67e74705SXin Li // CHECK-RS64: [3 x i8] @retChar3()
retChar3()54*67e74705SXin Li sChar3 retChar3() { sChar3 r; return r; }
55*67e74705SXin Li
56*67e74705SXin Li // CHECK-RS32: [2 x i16] @retShortChar()
57*67e74705SXin Li // CHECK-RS64: [2 x i16] @retShortChar()
retShortChar()58*67e74705SXin Li sShortChar retShortChar() { sShortChar r; return r; }
59*67e74705SXin Li
60*67e74705SXin Li // =============================================================================
61*67e74705SXin Li // aggregate parameter <= 16 bytes: coerced to [a x iNN] for both 32-bit and
62*67e74705SXin Li // 64-bit RenderScript
63*67e74705SXin Li // =============================================================================
64*67e74705SXin Li
65*67e74705SXin Li typedef struct {short s1; char c; short s2; } sShortCharShort;
66*67e74705SXin Li typedef struct {int i; short s; char c; } sIntShortChar;
67*67e74705SXin Li typedef struct {long l; int i; } sLongInt;
68*67e74705SXin Li
69*67e74705SXin Li // CHECK-RS32: void @argShortCharShort([3 x i16] %s.coerce)
70*67e74705SXin Li // CHECK-RS64: void @argShortCharShort([3 x i16] %s.coerce)
argShortCharShort(sShortCharShort s)71*67e74705SXin Li void argShortCharShort(sShortCharShort s) {}
72*67e74705SXin Li
73*67e74705SXin Li // CHECK-RS32: void @argIntShortChar([2 x i32] %s.coerce)
74*67e74705SXin Li // CHECK-RS64: void @argIntShortChar([2 x i32] %s.coerce)
argIntShortChar(sIntShortChar s)75*67e74705SXin Li void argIntShortChar(sIntShortChar s) {}
76*67e74705SXin Li
77*67e74705SXin Li // CHECK-RS32: void @argLongInt([2 x i64] %s.coerce)
78*67e74705SXin Li // CHECK-RS64: void @argLongInt([2 x i64] %s.coerce)
argLongInt(sLongInt s)79*67e74705SXin Li void argLongInt(sLongInt s) {}
80*67e74705SXin Li
81*67e74705SXin Li // =============================================================================
82*67e74705SXin Li // aggregate return value <= 16 bytes: returned on stack for 32-bit RenderScript
83*67e74705SXin Li // and coerced to [a x iNN] for 64-bit RenderScript
84*67e74705SXin Li // =============================================================================
85*67e74705SXin Li
86*67e74705SXin Li // CHECK-RS32: void @retShortCharShort(%struct.sShortCharShort* noalias sret %agg.result)
87*67e74705SXin Li // CHECK-RS64: [3 x i16] @retShortCharShort()
retShortCharShort()88*67e74705SXin Li sShortCharShort retShortCharShort() { sShortCharShort r; return r; }
89*67e74705SXin Li
90*67e74705SXin Li // CHECK-RS32: void @retIntShortChar(%struct.sIntShortChar* noalias sret %agg.result)
91*67e74705SXin Li // CHECK-RS64: [2 x i32] @retIntShortChar()
retIntShortChar()92*67e74705SXin Li sIntShortChar retIntShortChar() { sIntShortChar r; return r; }
93*67e74705SXin Li
94*67e74705SXin Li // CHECK-RS32: void @retLongInt(%struct.sLongInt* noalias sret %agg.result)
95*67e74705SXin Li // CHECK-RS64: [2 x i64] @retLongInt()
retLongInt()96*67e74705SXin Li sLongInt retLongInt() { sLongInt r; return r; }
97*67e74705SXin Li
98*67e74705SXin Li // =============================================================================
99*67e74705SXin Li // aggregate parameter <= 64 bytes: coerced to [a x iNN] for 32-bit RenderScript
100*67e74705SXin Li // and passed on the stack for 64-bit RenderScript
101*67e74705SXin Li // =============================================================================
102*67e74705SXin Li
103*67e74705SXin Li typedef struct {int i1, i2, i3, i4, i5; } sInt5;
104*67e74705SXin Li typedef struct {long l1, l2; char c; } sLong2Char;
105*67e74705SXin Li
106*67e74705SXin Li // CHECK-RS32: void @argInt5([5 x i32] %s.coerce)
107*67e74705SXin Li // CHECK-RS64: void @argInt5(%struct.sInt5* %s)
argInt5(sInt5 s)108*67e74705SXin Li void argInt5(sInt5 s) {}
109*67e74705SXin Li
110*67e74705SXin Li // CHECK-RS32: void @argLong2Char([3 x i64] %s.coerce)
111*67e74705SXin Li // CHECK-RS64: void @argLong2Char(%struct.sLong2Char* %s)
argLong2Char(sLong2Char s)112*67e74705SXin Li void argLong2Char(sLong2Char s) {}
113*67e74705SXin Li
114*67e74705SXin Li // =============================================================================
115*67e74705SXin Li // aggregate return value <= 64 bytes: returned on stack for both 32-bit and
116*67e74705SXin Li // 64-bit RenderScript
117*67e74705SXin Li // =============================================================================
118*67e74705SXin Li
119*67e74705SXin Li // CHECK-RS32: void @retInt5(%struct.sInt5* noalias sret %agg.result)
120*67e74705SXin Li // CHECK-RS64: void @retInt5(%struct.sInt5* noalias sret %agg.result)
retInt5()121*67e74705SXin Li sInt5 retInt5() { sInt5 r; return r;}
122*67e74705SXin Li
123*67e74705SXin Li // CHECK-RS32: void @retLong2Char(%struct.sLong2Char* noalias sret %agg.result)
124*67e74705SXin Li // CHECK-RS64: void @retLong2Char(%struct.sLong2Char* noalias sret %agg.result)
retLong2Char()125*67e74705SXin Li sLong2Char retLong2Char() { sLong2Char r; return r;}
126*67e74705SXin Li
127*67e74705SXin Li // =============================================================================
128*67e74705SXin Li // aggregate parameters and return values > 64 bytes: passed and returned on the
129*67e74705SXin Li // stack for both 32-bit and 64-bit RenderScript
130*67e74705SXin Li // =============================================================================
131*67e74705SXin Li
132*67e74705SXin Li typedef struct {long l1, l2, l3, l4, l5, l6, l7, l8, l9; } sLong9;
133*67e74705SXin Li
134*67e74705SXin Li // CHECK-RS32: void @argLong9(%struct.sLong9* byval align 8 %s)
135*67e74705SXin Li // CHECK-RS64: void @argLong9(%struct.sLong9* %s)
argLong9(sLong9 s)136*67e74705SXin Li void argLong9(sLong9 s) {}
137*67e74705SXin Li
138*67e74705SXin Li // CHECK-RS32: void @retLong9(%struct.sLong9* noalias sret %agg.result)
139*67e74705SXin Li // CHECK-RS64: void @retLong9(%struct.sLong9* noalias sret %agg.result)
retLong9()140*67e74705SXin Li sLong9 retLong9() { sLong9 r; return r; }
141