1 ; RUN: llc -march=bpfel -filetype=asm -o - %s | FileCheck %s
4 ; #define _(x) (__builtin_preserve_access_index(x))
5 ; struct s {int a; int b;};
6 ; int test(struct s *arg) { return *(const int *)_(&arg->b); }
7 ; Compiler flag to generate IR:
8 ; clang -target bpf -S -O2 -g -emit-llvm test.c
10 %struct.s = type { i32, i32 }
12 ; Function Attrs: nounwind readonly
13 define dso_local i32 @test(%struct.s* readonly %arg) local_unnamed_addr #0 !dbg !11 {
15 call void @llvm.dbg.value(metadata %struct.s* %arg, metadata !20, metadata !DIExpression()), !dbg !21
16 %0 = tail call i32* @llvm.preserve.struct.access.index.p0i32.p0s_struct.ss(%struct.s* %arg, i32 1, i32 1), !dbg !22, !llvm.preserve.access.index !15
17 %1 = load i32, i32* %0, align 4, !dbg !23, !tbaa !24
24 ; CHECK: r0 = *(u32 *)(r1 + 0)
27 ; CHECK: .long 1 # BTF_KIND_STRUCT(id = 2)
29 ; CHECK: .byte 115 # string offset=1
30 ; CHECK: .ascii ".text" # string offset=20
31 ; CHECK: .ascii "0:1" # string offset=26
33 ; CHECK: .long 16 # FieldReloc
34 ; CHECK-NEXT: .long 20 # Field reloc section string offset=20
36 ; CHECK-NEXT: .long .Ltmp{{[0-9]+}}
38 ; CHECK-NEXT: .long 26
41 ; Function Attrs: nounwind readnone
42 declare i32* @llvm.preserve.struct.access.index.p0i32.p0s_struct.ss(%struct.s*, i32, i32) #1
44 ; Function Attrs: nounwind readnone speculatable willreturn
45 declare void @llvm.dbg.value(metadata, metadata, metadata) #2
47 attributes #0 = { nounwind readonly "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" }
48 attributes #1 = { nounwind readnone }
49 attributes #2 = { nounwind readnone speculatable willreturn }
52 !llvm.module.flags = !{!7, !8, !9}
55 !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 10.0.0 (https://github.com/llvm/llvm-project.git 6e353b4df3aa452ed4741a5e5caea02b1a876d8c)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !3, nameTableKind: None)
56 !1 = !DIFile(filename: "test.c", directory: "/tmp/home/yhs/work/tests/core")
59 !4 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !5, size: 64)
60 !5 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !6)
61 !6 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
62 !7 = !{i32 2, !"Dwarf Version", i32 4}
63 !8 = !{i32 2, !"Debug Info Version", i32 3}
64 !9 = !{i32 1, !"wchar_size", i32 4}
65 !10 = !{!"clang version 10.0.0 (https://github.com/llvm/llvm-project.git 6e353b4df3aa452ed4741a5e5caea02b1a876d8c)"}
66 !11 = distinct !DISubprogram(name: "test", scope: !1, file: !1, line: 3, type: !12, scopeLine: 3, flags: DIFlagPrototyped, isDefinition: true, isOptimized: true, unit: !0, retainedNodes: !19)
67 !12 = !DISubroutineType(types: !13)
69 !14 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !15, size: 64)
70 !15 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "s", file: !1, line: 2, size: 64, elements: !16)
72 !17 = !DIDerivedType(tag: DW_TAG_member, name: "a", scope: !15, file: !1, line: 2, baseType: !6, size: 32)
73 !18 = !DIDerivedType(tag: DW_TAG_member, name: "b", scope: !15, file: !1, line: 2, baseType: !6, size: 32, offset: 32)
75 !20 = !DILocalVariable(name: "arg", arg: 1, scope: !11, file: !1, line: 3, type: !14)
76 !21 = !DILocation(line: 0, scope: !11)
77 !22 = !DILocation(line: 3, column: 48, scope: !11)
78 !23 = !DILocation(line: 3, column: 34, scope: !11)
79 !24 = !{!25, !25, i64 0}
80 !25 = !{!"int", !26, i64 0}
81 !26 = !{!"omnipotent char", !27, i64 0}
82 !27 = !{!"Simple C/C++ TBAA"}
83 !28 = !DILocation(line: 3, column: 27, scope: !11)