1 ; RUN: opt -O2 %s | llvm-dis > %t1
2 ; RUN: llc -filetype=asm -o - %t1 | FileCheck -check-prefixes=CHECK %s
3 ; RUN: llc -mattr=+alu32 -filetype=asm -o - %t1 | FileCheck -check-prefixes=CHECK %s
5 ; struct v1 {int a; int b;};
6 ; typedef struct v1 __v1;
8 ; struct v3 { char c; int d[100]; };
9 ; #define _(x) (__builtin_preserve_access_index(x))
10 ; #define cast_to_arr(x) ((arr *)(x))
11 ; int get_value(const int *arg);
12 ; int test(struct v3 *arg) {
13 ; return get_value(_(&cast_to_arr(&arg->d[0])[0][2].b));
16 ; clang -target bpf -O2 -g -S -emit-llvm -Xclang -disable-llvm-passes test.c
20 %struct.v3 = type { i8, [100 x i32] }
21 %struct.v1 = type { i32, i32 }
23 ; Function Attrs: nounwind
24 define dso_local i32 @test(ptr %arg) local_unnamed_addr #0 !dbg !22 {
26 call void @llvm.dbg.value(metadata ptr %arg, metadata !32, metadata !DIExpression()), !dbg !33
27 %0 = tail call ptr @llvm.preserve.struct.access.index.p0.p0(ptr elementtype(%struct.v3) %arg, i32 1, i32 1), !dbg !34, !llvm.preserve.access.index !26
28 %1 = tail call ptr @llvm.preserve.array.access.index.p0.p0(ptr elementtype([100 x i32]) %0, i32 1, i32 0), !dbg !34, !llvm.preserve.access.index !15
29 %2 = bitcast ptr %1 to ptr, !dbg !34
30 %3 = tail call ptr @llvm.preserve.array.access.index.p0.p0(ptr elementtype([4 x %struct.v1]) %2, i32 0, i32 0), !dbg !34, !llvm.preserve.access.index !4
31 %4 = tail call ptr @llvm.preserve.array.access.index.p0.p0(ptr elementtype([4 x %struct.v1]) %3, i32 1, i32 2), !dbg !34, !llvm.preserve.access.index !5
32 %5 = tail call ptr @llvm.preserve.struct.access.index.p0.p0(ptr elementtype(%struct.v1) %4, i32 1, i32 1), !dbg !34, !llvm.preserve.access.index !8
33 %call = tail call i32 @get_value(ptr %5) #4, !dbg !35
34 ret i32 %call, !dbg !36
41 ; CHECK: call get_value
43 ; CHECK: .long 1 # BTF_KIND_STRUCT(id = [[TID1:[0-9]+]])
44 ; CHECK: .long 100 # BTF_KIND_STRUCT(id = [[TID2:[0-9]+]])
46 ; CHECK: .ascii "v3" # string offset=1
47 ; CHECK: .ascii ".text" # string offset=46
48 ; CHECK: .ascii "0:1:0" # string offset=52
49 ; CHECK: .ascii "2:1" # string offset=107
51 ; CHECK: .long 16 # FieldReloc
52 ; CHECK-NEXT: .long 46 # Field reloc section string offset=46
54 ; CHECK-NEXT: .long .Ltmp{{[0-9]+}}
55 ; CHECK-NEXT: .long [[TID1]]
56 ; CHECK-NEXT: .long 52
58 ; CHECK-NEXT: .long .Ltmp{{[0-9]+}}
59 ; CHECK-NEXT: .long [[TID2]]
60 ; CHECK-NEXT: .long 107
63 declare dso_local i32 @get_value(ptr) local_unnamed_addr #1
65 ; Function Attrs: nounwind readnone
66 declare ptr @llvm.preserve.struct.access.index.p0.p0(ptr, i32, i32) #2
68 ; Function Attrs: nounwind readnone
69 declare ptr @llvm.preserve.array.access.index.p0.p0(ptr, i32, i32) #2
71 ; Function Attrs: nounwind readnone
73 ; Function Attrs: nounwind readnone
75 ; Function Attrs: nounwind readnone
77 ; Function Attrs: nounwind readnone speculatable willreturn
78 declare void @llvm.dbg.value(metadata, metadata, metadata) #3
80 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" }
81 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" }
82 attributes #2 = { nounwind readnone }
83 attributes #3 = { nounwind readnone speculatable willreturn }
84 attributes #4 = { nounwind }
87 !llvm.module.flags = !{!18, !19, !20}
90 !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)
91 !1 = !DIFile(filename: "test.c", directory: "/tmp/home/yhs/work/tests/llvm/cast")
94 !4 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !5, size: 64)
95 !5 = !DIDerivedType(tag: DW_TAG_typedef, name: "arr", file: !1, line: 3, baseType: !6)
96 !6 = !DICompositeType(tag: DW_TAG_array_type, baseType: !7, size: 256, elements: !13)
97 !7 = !DIDerivedType(tag: DW_TAG_typedef, name: "__v1", file: !1, line: 2, baseType: !8)
98 !8 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "v1", file: !1, line: 1, size: 64, elements: !9)
100 !10 = !DIDerivedType(tag: DW_TAG_member, name: "a", scope: !8, file: !1, line: 1, baseType: !11, size: 32)
101 !11 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
102 !12 = !DIDerivedType(tag: DW_TAG_member, name: "b", scope: !8, file: !1, line: 1, baseType: !11, size: 32, offset: 32)
104 !14 = !DISubrange(count: 4)
105 !15 = !DICompositeType(tag: DW_TAG_array_type, baseType: !11, size: 3200, elements: !16)
107 !17 = !DISubrange(count: 100)
108 !18 = !{i32 2, !"Dwarf Version", i32 4}
109 !19 = !{i32 2, !"Debug Info Version", i32 3}
110 !20 = !{i32 1, !"wchar_size", i32 4}
111 !21 = !{!"clang version 10.0.0 (trunk 367256) (llvm/trunk 367266)"}
112 !22 = distinct !DISubprogram(name: "test", scope: !1, file: !1, line: 8, type: !23, scopeLine: 8, flags: DIFlagPrototyped, isDefinition: true, isOptimized: true, unit: !0, retainedNodes: !31)
113 !23 = !DISubroutineType(types: !24)
115 !25 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !26, size: 64)
116 !26 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "v3", file: !1, line: 4, size: 3232, elements: !27)
118 !28 = !DIDerivedType(tag: DW_TAG_member, name: "c", scope: !26, file: !1, line: 4, baseType: !29, size: 8)
119 !29 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char)
120 !30 = !DIDerivedType(tag: DW_TAG_member, name: "d", scope: !26, file: !1, line: 4, baseType: !15, size: 3200, offset: 32)
122 !32 = !DILocalVariable(name: "arg", arg: 1, scope: !22, file: !1, line: 8, type: !25)
123 !33 = !DILocation(line: 0, scope: !22)
124 !34 = !DILocation(line: 9, column: 20, scope: !22)
125 !35 = !DILocation(line: 9, column: 10, scope: !22)
126 !36 = !DILocation(line: 9, column: 3, scope: !22)