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 4; Source code: 5; struct t1 { 6; int c; 7; }; 8; struct s1 { 9; struct t1 b; 10; }; 11; struct r1 { 12; struct s1 a; 13; }; 14; #define _(x) __builtin_preserve_access_index(x) 15; void test1(ptr p1, ptr p2, ptr p3); 16; void test(struct r1 *arg) { 17; struct s1 *ps = _(&arg->a); 18; struct t1 *pt = _(&arg->a.b); 19; int *pi = _(&arg->a.b.c); 20; test1(ps, pt, pi); 21; } 22; Compilation flag: 23; clang -target bpf -O2 -g -S -emit-llvm -Xclang -disable-llvm-passes test.c 24 25target triple = "bpf" 26 27%struct.r1 = type { %struct.s1 } 28%struct.s1 = type { %struct.t1 } 29%struct.t1 = type { i32 } 30 31; Function Attrs: nounwind 32define dso_local void @test(ptr %arg) local_unnamed_addr #0 !dbg !7 { 33entry: 34 call void @llvm.dbg.value(metadata ptr %arg, metadata !22, metadata !DIExpression()), !dbg !29 35 %0 = tail call ptr @llvm.preserve.struct.access.index.p0.s1s.p0.r1s(ptr elementtype(%struct.r1) %arg, i32 0, i32 0), !dbg !30, !llvm.preserve.access.index !11 36 call void @llvm.dbg.value(metadata ptr %0, metadata !23, metadata !DIExpression()), !dbg !29 37 %1 = tail call ptr @llvm.preserve.struct.access.index.p0.t1s.p0.s1s(ptr elementtype(%struct.s1) %0, i32 0, i32 0), !dbg !31, !llvm.preserve.access.index !14 38 call void @llvm.dbg.value(metadata ptr %1, metadata !25, metadata !DIExpression()), !dbg !29 39 %2 = tail call ptr @llvm.preserve.struct.access.index.p0.p0.t1s(ptr elementtype(%struct.t1) %1, i32 0, i32 0), !dbg !32, !llvm.preserve.access.index !17 40 call void @llvm.dbg.value(metadata ptr %2, metadata !27, metadata !DIExpression()), !dbg !29 41 tail call void @test1(ptr %0, ptr %1, ptr %2) #4, !dbg !36 42 ret void, !dbg !37 43} 44 45; CHECK: .long 1 # BTF_KIND_STRUCT(id = 2) 46 47; CHECK: .ascii "r1" # string offset=1 48; CHECK: .ascii ".text" # string offset=29 49; CHECK: .ascii "0:0" # string offset=72 50; CHECK: .ascii "0:0:0" # string offset=76 51; CHECK: .ascii "0:0:0:0" # string offset=82 52 53; CHECK: .long 16 # FieldReloc 54; CHECK-NEXT: .long 29 # Field reloc section string offset=29 55; CHECK-NEXT: .long 3 56; CHECK-NEXT: .long .Ltmp{{[0-9]+}} 57; CHECK-NEXT: .long 2 58; CHECK-NEXT: .long 72 59; CHECK-NEXT: .long 0 60; CHECK-NEXT: .long .Ltmp{{[0-9]+}} 61; CHECK-NEXT: .long 2 62; CHECK-NEXT: .long 76 63; CHECK-NEXT: .long 0 64; CHECK-NEXT: .long .Ltmp{{[0-9]+}} 65; CHECK-NEXT: .long 2 66; CHECK-NEXT: .long 82 67; CHECK-NEXT: .long 0 68 69; Function Attrs: nounwind readnone 70declare ptr @llvm.preserve.struct.access.index.p0.s1s.p0.r1s(ptr, i32, i32) #1 71 72; Function Attrs: nounwind readnone 73declare ptr @llvm.preserve.struct.access.index.p0.t1s.p0.s1s(ptr, i32, i32) #1 74 75; Function Attrs: nounwind readnone 76declare ptr @llvm.preserve.struct.access.index.p0.p0.t1s(ptr, i32, i32) #1 77 78declare dso_local void @test1(ptr, ptr, ptr) local_unnamed_addr #2 79 80; Function Attrs: nounwind readnone speculatable willreturn 81declare void @llvm.dbg.value(metadata, metadata, metadata) #3 82 83attributes #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" } 84attributes #1 = { nounwind readnone } 85attributes #2 = { "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" } 86attributes #3 = { nounwind readnone speculatable willreturn } 87attributes #4 = { nounwind } 88 89!llvm.dbg.cu = !{!0} 90!llvm.module.flags = !{!3, !4, !5} 91!llvm.ident = !{!6} 92 93!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 10.0.0 (https://github.com/llvm/llvm-project.git 42b3328a2368b38fba6bdb0c616fe6c5520e3bc5)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, nameTableKind: None) 94!1 = !DIFile(filename: "test.c", directory: "/tmp/home/yhs/work/tests/core") 95!2 = !{} 96!3 = !{i32 2, !"Dwarf Version", i32 4} 97!4 = !{i32 2, !"Debug Info Version", i32 3} 98!5 = !{i32 1, !"wchar_size", i32 4} 99!6 = !{!"clang version 10.0.0 (https://github.com/llvm/llvm-project.git 42b3328a2368b38fba6bdb0c616fe6c5520e3bc5)"} 100!7 = distinct !DISubprogram(name: "test", scope: !1, file: !1, line: 12, type: !8, scopeLine: 12, flags: DIFlagPrototyped, isDefinition: true, isOptimized: true, unit: !0, retainedNodes: !21) 101!8 = !DISubroutineType(types: !9) 102!9 = !{null, !10} 103!10 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !11, size: 64) 104!11 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "r1", file: !1, line: 7, size: 32, elements: !12) 105!12 = !{!13} 106!13 = !DIDerivedType(tag: DW_TAG_member, name: "a", scope: !11, file: !1, line: 8, baseType: !14, size: 32) 107!14 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "s1", file: !1, line: 4, size: 32, elements: !15) 108!15 = !{!16} 109!16 = !DIDerivedType(tag: DW_TAG_member, name: "b", scope: !14, file: !1, line: 5, baseType: !17, size: 32) 110!17 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "t1", file: !1, line: 1, size: 32, elements: !18) 111!18 = !{!19} 112!19 = !DIDerivedType(tag: DW_TAG_member, name: "c", scope: !17, file: !1, line: 2, baseType: !20, size: 32) 113!20 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) 114!21 = !{!22, !23, !25, !27} 115!22 = !DILocalVariable(name: "arg", arg: 1, scope: !7, file: !1, line: 12, type: !10) 116!23 = !DILocalVariable(name: "ps", scope: !7, file: !1, line: 13, type: !24) 117!24 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !14, size: 64) 118!25 = !DILocalVariable(name: "pt", scope: !7, file: !1, line: 14, type: !26) 119!26 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !17, size: 64) 120!27 = !DILocalVariable(name: "pi", scope: !7, file: !1, line: 15, type: !28) 121!28 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !20, size: 64) 122!29 = !DILocation(line: 0, scope: !7) 123!30 = !DILocation(line: 13, column: 19, scope: !7) 124!31 = !DILocation(line: 14, column: 19, scope: !7) 125!32 = !DILocation(line: 15, column: 13, scope: !7) 126!33 = !DILocation(line: 16, column: 9, scope: !7) 127!34 = !DILocation(line: 16, column: 13, scope: !7) 128!35 = !DILocation(line: 16, column: 17, scope: !7) 129!36 = !DILocation(line: 16, column: 3, scope: !7) 130!37 = !DILocation(line: 17, column: 1, scope: !7) 131