1 ; RUN: llc -march=bpfel -filetype=asm -o - %s | FileCheck %s
4 ; union u { int a; int b; };
5 ; #define _(x) (__builtin_preserve_access_index(x))
6 ; int get_value(const void *addr);
7 ; int test(union u *arg) { return get_value(_(&arg->b)); }
8 ; Compiler flag to generate IR:
9 ; clang -target bpf -S -O2 -g -emit-llvm test.c
11 %union.u = type { i32 }
13 ; Function Attrs: nounwind
14 define dso_local i32 @test(%union.u* %arg) local_unnamed_addr #0 !dbg !7 {
16 call void @llvm.dbg.value(metadata %union.u* %arg, metadata !17, metadata !DIExpression()), !dbg !18
17 %0 = tail call %union.u* @llvm.preserve.union.access.index.p0s_union.us.p0s_union.us(%union.u* %arg, i32 1), !dbg !19, !llvm.preserve.access.index !12
18 %1 = bitcast %union.u* %0 to i8*, !dbg !19
19 %call = tail call i32 @get_value(i8* %1) #4, !dbg !20
20 ret i32 %call, !dbg !21
23 ; CHECK: [[RELOC:.Ltmp[0-9]+]]
26 ; CHECK: call get_value
29 ; CHECK: .section .BTF.ext,"",@progbits
30 ; CHECK: .long 16 # FieldReloc
31 ; CHECK-NEXT: .long 20 # Field reloc section string offset=20
33 ; CHECK-NEXT: .long [[RELOC]]
35 ; CHECK-NEXT: .long 26
38 declare dso_local i32 @get_value(i8*) local_unnamed_addr #1
40 ; Function Attrs: nounwind readnone
41 declare %union.u* @llvm.preserve.union.access.index.p0s_union.us.p0s_union.us(%union.u*, i32 immarg) #2
43 ; Function Attrs: nounwind readnone speculatable
44 declare void @llvm.dbg.value(metadata, metadata, metadata) #3
46 attributes #0 = { nounwind "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "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" }
47 attributes #1 = { "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "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" }
48 attributes #2 = { nounwind readnone }
49 attributes #3 = { nounwind readnone speculatable }
50 attributes #4 = { nounwind }
53 !llvm.module.flags = !{!3, !4, !5}
56 !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 9.0.0 (trunk 365789)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, nameTableKind: None)
57 !1 = !DIFile(filename: "test.c", directory: "/tmp/home/yhs/work/tests/core")
59 !3 = !{i32 2, !"Dwarf Version", i32 4}
60 !4 = !{i32 2, !"Debug Info Version", i32 3}
61 !5 = !{i32 1, !"wchar_size", i32 4}
62 !6 = !{!"clang version 9.0.0 (trunk 365789)"}
63 !7 = distinct !DISubprogram(name: "test", scope: !1, file: !1, line: 4, type: !8, scopeLine: 4, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !16)
64 !8 = !DISubroutineType(types: !9)
66 !10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
67 !11 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !12, size: 64)
68 !12 = distinct !DICompositeType(tag: DW_TAG_union_type, name: "u", file: !1, line: 1, size: 32, elements: !13)
70 !14 = !DIDerivedType(tag: DW_TAG_member, name: "a", scope: !12, file: !1, line: 1, baseType: !10, size: 32)
71 !15 = !DIDerivedType(tag: DW_TAG_member, name: "b", scope: !12, file: !1, line: 1, baseType: !10, size: 32)
73 !17 = !DILocalVariable(name: "arg", arg: 1, scope: !7, file: !1, line: 4, type: !11)
74 !18 = !DILocation(line: 0, scope: !7)
75 !19 = !DILocation(line: 4, column: 43, scope: !7)
76 !20 = !DILocation(line: 4, column: 33, scope: !7)
77 !21 = !DILocation(line: 4, column: 26, scope: !7)