• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// RUN: %Slang %s
2
3// RUN: %rs-filecheck-wrapper %s --check-prefix=CHECK-LL
4//     Check that the data type small_struct is properly padded:
5// CHECK-LL: %struct.small_struct{{(\.[0-9]+)?}} = type { i32, [4 x i8], i64 }
6//     Check that the helper function for unpacking an invokable's arguments
7//     accesses a properly padded struct:
8// CHECK-LL: define void @.helper_checkStruct({ i32, [4 x i8], i64 }* nocapture)
9// CHECK-LL: [[FIELD_I_ADDR:%[0-9]+]] = getelementptr inbounds { i32, [4 x i8], i64 }, { i32, [4 x i8], i64 }* %0, i{{[0-9]+}} 0, i32 0
10// CHECK-LL: [[FIELD_I_VAL:%[0-9]+]] = load i32, i32* [[FIELD_I_ADDR]]
11// CHECK-LL: [[FIELD_L_ADDR:%[0-9]+]] = getelementptr inbounds { i32, [4 x i8], i64 }, { i32, [4 x i8], i64 }* %0, i{{[0-9]+}} 0, i32 2
12// CHECK-LL: [[FIELD_L_VAL:%[0-9]+]] = load i64, i64* [[FIELD_L_ADDR]]
13// CHECK-LL: call void @checkStruct(i32 [[FIELD_I_VAL]], i64 [[FIELD_L_VAL]])
14
15// RUN: %scriptc-filecheck-wrapper --lang=Java --type=small_struct --check-prefix=CHECK-JAVA-STRUCT %s
16// CHECK-JAVA-STRUCT:      public static Element createElement(RenderScript rs) {
17// CHECK-JAVA-STRUCT-NEXT:     Element.Builder eb = new Element.Builder(rs);
18// CHECK-JAVA-STRUCT-NEXT:     eb.add(Element.I32(rs), "i");
19// CHECK-JAVA-STRUCT-NEXT:     eb.add(Element.U32(rs), "#rs_padding_1");
20// CHECK-JAVA-STRUCT-NEXT:     eb.add(Element.I64(rs), "l");
21// CHECK-JAVA-STRUCT-NEXT:     return eb.create();
22// CHECK-JAVA-STRUCT-NEXT: }
23
24// RUN: %scriptc-filecheck-wrapper --lang=Java --check-prefix=CHECK-JAVA-INVOKE %s
25// CHECK-JAVA-INVOKE:      public void invoke_checkStruct(int argI, long argL) {
26// CHECK-JAVA-INVOKE-NEXT:     FieldPacker checkStruct_fp = new FieldPacker(16);
27// CHECK-JAVA-INVOKE-NEXT:     checkStruct_fp.addI32(argI);
28// CHECK-JAVA-INVOKE-NEXT:     checkStruct_fp.skip(4);
29// CHECK-JAVA-INVOKE-NEXT:     checkStruct_fp.addI64(argL);
30// CHECK-JAVA-INVOKE-NEXT:     invoke(mExportFuncIdx_checkStruct, checkStruct_fp);
31// CHECK-JAVA-INVOKE-NEXT: }
32
33// Same as small_struct_2.rs except for order of fields (hence location of padding) in struct small_struct[_2].
34
35#pragma version(1)
36#pragma rs java_package_name(foo)
37
38typedef struct small_struct {
39    int i;
40    // expect 4 bytes of padding here
41    long l;
42} small_struct;
43
44small_struct g_small_struct;
45
46bool failed = false;
47
48void checkStruct(int argI, long argL) {
49    failed |= ((g_small_struct.i != argI) || (g_small_struct.l != argL));
50}
51