1 ; RUN: llc -march=bpfel -filetype=asm -o - %s | FileCheck -check-prefixes=CHECK %s
2 ; RUN: llc -march=bpfeb -filetype=asm -o - %s | FileCheck -check-prefixes=CHECK %s
4 ; struct v1 {int a; int b;};
5 ; typedef struct v1 __v1;
6 ; typedef __v1 arr[4][4];
7 ; struct v3 { char c; int d[100]; };
8 ; #define _(x) (__builtin_preserve_access_index(x))
9 ; #define cast_to_arr(x) ((arr *)(x))
10 ; int get_value(const int *arg);
11 ; int test(struct v3 *arg) {
12 ; return get_value(_(&cast_to_arr(&arg->d[0])[0][2][3].b));
15 ; clang -target bpf -O2 -g -S -emit-llvm test.c
17 %struct.v3 = type { i8, [100 x i32] }
18 %struct.v1 = type { i32, i32 }
20 ; Function Attrs: nounwind
21 define dso_local i32 @test(%struct.v3* %arg) local_unnamed_addr #0 !dbg !24 {
23 call void @llvm.dbg.value(metadata %struct.v3* %arg, metadata !34, metadata !DIExpression()), !dbg !35
24 %0 = tail call [100 x i32]* @llvm.preserve.struct.access.index.p0a100i32.p0s_struct.v3s(%struct.v3* %arg, i32 1, i32 1), !dbg !36, !llvm.preserve.access.index !28
25 %1 = tail call i32* @llvm.preserve.array.access.index.p0i32.p0a100i32([100 x i32]* %0, i32 1, i32 0), !dbg !36, !llvm.preserve.access.index !15
26 %2 = bitcast i32* %1 to [4 x [4 x %struct.v1]]*, !dbg !36
27 %3 = tail call [4 x [4 x %struct.v1]]* @llvm.preserve.array.access.index.p0a4a4s_struct.v1s.p0a4a4s_struct.v1s([4 x [4 x %struct.v1]]* %2, i32 0, i32 0), !dbg !36, !llvm.preserve.access.index !4
28 %4 = tail call [4 x %struct.v1]* @llvm.preserve.array.access.index.p0a4s_struct.v1s.p0a4a4s_struct.v1s([4 x [4 x %struct.v1]]* %3, i32 1, i32 2), !dbg !36, !llvm.preserve.access.index !5
29 %5 = tail call %struct.v1* @llvm.preserve.array.access.index.p0s_struct.v1s.p0a4s_struct.v1s([4 x %struct.v1]* %4, i32 1, i32 3), !dbg !36, !llvm.preserve.access.index !18
30 %6 = tail call i32* @llvm.preserve.struct.access.index.p0i32.p0s_struct.v1s(%struct.v1* %5, i32 1, i32 1), !dbg !36, !llvm.preserve.access.index !8
31 %call = tail call i32 @get_value(i32* %6) #4, !dbg !37
32 ret i32 %call, !dbg !38
39 ; CHECK: call get_value
41 ; CHECK: .long 1 # BTF_KIND_STRUCT(id = [[TID1:[0-9]+]])
42 ; CHECK: .long 100 # BTF_KIND_STRUCT(id = [[TID2:[0-9]+]])
44 ; CHECK: .ascii "v3" # string offset=1
45 ; CHECK: .ascii ".text" # string offset=46
46 ; CHECK: .ascii "0:1:0" # string offset=52
47 ; CHECK: .ascii "v1" # string offset=100
48 ; CHECK: .ascii "11:1" # string offset=107
50 ; CHECK: .long 16 # FieldReloc
51 ; CHECK-NEXT: .long 46 # Field reloc section string offset=46
53 ; CHECK-NEXT: .long .Ltmp{{[0-9]+}}
54 ; CHECK-NEXT: .long [[TID1]]
55 ; CHECK-NEXT: .long 52
57 ; CHECK-NEXT: .long .Ltmp{{[0-9]+}}
58 ; CHECK-NEXT: .long [[TID2]]
59 ; CHECK-NEXT: .long 107
62 declare dso_local i32 @get_value(i32*) local_unnamed_addr #1
64 ; Function Attrs: nounwind readnone
65 declare [100 x i32]* @llvm.preserve.struct.access.index.p0a100i32.p0s_struct.v3s(%struct.v3*, i32, i32) #2
67 ; Function Attrs: nounwind readnone
68 declare i32* @llvm.preserve.array.access.index.p0i32.p0a100i32([100 x i32]*, i32, i32) #2
70 ; Function Attrs: nounwind readnone
71 declare [4 x [4 x %struct.v1]]* @llvm.preserve.array.access.index.p0a4a4s_struct.v1s.p0a4a4s_struct.v1s([4 x [4 x %struct.v1]]*, i32, i32) #2
73 ; Function Attrs: nounwind readnone
74 declare [4 x %struct.v1]* @llvm.preserve.array.access.index.p0a4s_struct.v1s.p0a4a4s_struct.v1s([4 x [4 x %struct.v1]]*, i32, i32) #2
76 ; Function Attrs: nounwind readnone
77 declare %struct.v1* @llvm.preserve.array.access.index.p0s_struct.v1s.p0a4s_struct.v1s([4 x %struct.v1]*, i32, i32) #2
79 ; Function Attrs: nounwind readnone
80 declare i32* @llvm.preserve.struct.access.index.p0i32.p0s_struct.v1s(%struct.v1*, i32, i32) #2
82 ; Function Attrs: nounwind readnone speculatable willreturn
83 declare void @llvm.dbg.value(metadata, metadata, metadata) #3
85 attributes #0 = { nounwind "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="all" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
86 attributes #1 = { "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="all" "less-precise-fpmad"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
87 attributes #2 = { nounwind readnone }
88 attributes #3 = { nounwind readnone speculatable willreturn }
89 attributes #4 = { nounwind }
92 !llvm.module.flags = !{!20, !21, !22}
95 !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 10.0.0 (trunk 367256) (llvm/trunk 367266)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !3, nameTableKind: None)
96 !1 = !DIFile(filename: "test.c", directory: "/tmp/home/yhs/work/tests/llvm/cast")
98 !3 = !{!4, !15, !5, !18}
99 !4 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !5, size: 64)
100 !5 = !DIDerivedType(tag: DW_TAG_typedef, name: "arr", file: !1, line: 3, baseType: !6)
101 !6 = !DICompositeType(tag: DW_TAG_array_type, baseType: !7, size: 1024, elements: !13)
102 !7 = !DIDerivedType(tag: DW_TAG_typedef, name: "__v1", file: !1, line: 2, baseType: !8)
103 !8 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "v1", file: !1, line: 1, size: 64, elements: !9)
105 !10 = !DIDerivedType(tag: DW_TAG_member, name: "a", scope: !8, file: !1, line: 1, baseType: !11, size: 32)
106 !11 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
107 !12 = !DIDerivedType(tag: DW_TAG_member, name: "b", scope: !8, file: !1, line: 1, baseType: !11, size: 32, offset: 32)
109 !14 = !DISubrange(count: 4)
110 !15 = !DICompositeType(tag: DW_TAG_array_type, baseType: !11, size: 3200, elements: !16)
112 !17 = !DISubrange(count: 100)
113 !18 = !DICompositeType(tag: DW_TAG_array_type, baseType: !7, size: 256, elements: !19)
115 !20 = !{i32 2, !"Dwarf Version", i32 4}
116 !21 = !{i32 2, !"Debug Info Version", i32 3}
117 !22 = !{i32 1, !"wchar_size", i32 4}
118 !23 = !{!"clang version 10.0.0 (trunk 367256) (llvm/trunk 367266)"}
119 !24 = distinct !DISubprogram(name: "test", scope: !1, file: !1, line: 8, type: !25, scopeLine: 8, flags: DIFlagPrototyped, isDefinition: true, isOptimized: true, unit: !0, retainedNodes: !33)
120 !25 = !DISubroutineType(types: !26)
122 !27 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !28, size: 64)
123 !28 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "v3", file: !1, line: 4, size: 3232, elements: !29)
125 !30 = !DIDerivedType(tag: DW_TAG_member, name: "c", scope: !28, file: !1, line: 4, baseType: !31, size: 8)
126 !31 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char)
127 !32 = !DIDerivedType(tag: DW_TAG_member, name: "d", scope: !28, file: !1, line: 4, baseType: !15, size: 3200, offset: 32)
129 !34 = !DILocalVariable(name: "arg", arg: 1, scope: !24, file: !1, line: 8, type: !27)
130 !35 = !DILocation(line: 0, scope: !24)
131 !36 = !DILocation(line: 9, column: 20, scope: !24)
132 !37 = !DILocation(line: 9, column: 10, scope: !24)
133 !38 = !DILocation(line: 9, column: 3, scope: !24)