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 ; struct v2 { int c; int d; };
6 ; struct v3 { char c; struct v2 d; };
7 ; #define _(x) (__builtin_preserve_access_index(x))
8 ; #define cast_to_v1(x) ((struct v1 *)(x))
9 ; int get_value(const int *arg);
10 ; int test(struct v3 *arg) {
11 ; return get_value(_(&cast_to_v1(&arg->d)->b));
14 ; clang -target bpf -O2 -g -S -emit-llvm test.c
16 %struct.v3 = type { i8, %struct.v2 }
17 %struct.v2 = type { i32, 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 !14 {
23 call void @llvm.dbg.value(metadata %struct.v3* %arg, metadata !28, metadata !DIExpression()), !dbg !29
24 %0 = tail call %struct.v2* @llvm.preserve.struct.access.index.p0s_struct.v2s.p0s_struct.v3s(%struct.v3* %arg, i32 1, i32 1), !dbg !30, !llvm.preserve.access.index !18
25 %1 = bitcast %struct.v2* %0 to %struct.v1*, !dbg !30
26 %2 = tail call i32* @llvm.preserve.struct.access.index.p0i32.p0s_struct.v1s(%struct.v1* %1, i32 1, i32 1), !dbg !30, !llvm.preserve.access.index !5
27 %call = tail call i32 @get_value(i32* %2) #4, !dbg !31
28 ret i32 %call, !dbg !32
35 ; CHECK: call get_value
37 ; CHECK: .long 1 # BTF_KIND_STRUCT(id = [[V3_TID:[0-9]+]])
38 ; CHECK: .long 81 # BTF_KIND_STRUCT(id = [[V1_TID:[0-9]+]])
40 ; CHECK: .ascii "v3" # string offset=1
42 ; CHECK: .ascii ".text" # string offset=[[SEC_STR:[0-9]+]]
44 ; CHECK: .ascii "0:1" # string offset=[[ACCESS_STR:[0-9]+]]
46 ; CHECK: .ascii "v1" # string offset=81
49 ; CHECK: .long 16 # FieldReloc
50 ; CHECK-NEXT: .long [[SEC_STR]] # Field reloc section string offset=[[SEC_STR]]
52 ; CHECK-NEXT: .long .Ltmp{{[0-9]+}}
53 ; CHECK-NEXT: .long [[V3_TID]]
54 ; CHECK-NEXT: .long [[ACCESS_STR]]
56 ; CHECK-NEXT: .long .Ltmp{{[0-9]+}}
57 ; CHECK-NEXT: .long [[V1_TID]]
58 ; CHECK-NEXT: .long [[ACCESS_STR]]
61 declare dso_local i32 @get_value(i32*) local_unnamed_addr #1
63 ; Function Attrs: nounwind readnone
64 declare %struct.v2* @llvm.preserve.struct.access.index.p0s_struct.v2s.p0s_struct.v3s(%struct.v3*, i32, i32) #2
66 ; Function Attrs: nounwind readnone
67 declare i32* @llvm.preserve.struct.access.index.p0i32.p0s_struct.v1s(%struct.v1*, i32, i32) #2
69 ; Function Attrs: nounwind readnone speculatable willreturn
70 declare void @llvm.dbg.value(metadata, metadata, metadata) #3
72 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" }
73 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" }
74 attributes #2 = { nounwind readnone }
75 attributes #3 = { nounwind readnone speculatable willreturn }
76 attributes #4 = { nounwind }
79 !llvm.module.flags = !{!10, !11, !12}
82 !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)
83 !1 = !DIFile(filename: "test.c", directory: "/tmp/home/yhs/work/tests/llvm/cast")
86 !4 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !5, size: 64)
87 !5 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "v1", file: !1, line: 1, size: 64, elements: !6)
89 !7 = !DIDerivedType(tag: DW_TAG_member, name: "a", scope: !5, file: !1, line: 1, baseType: !8, size: 32)
90 !8 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
91 !9 = !DIDerivedType(tag: DW_TAG_member, name: "b", scope: !5, file: !1, line: 1, baseType: !8, size: 32, offset: 32)
92 !10 = !{i32 2, !"Dwarf Version", i32 4}
93 !11 = !{i32 2, !"Debug Info Version", i32 3}
94 !12 = !{i32 1, !"wchar_size", i32 4}
95 !13 = !{!"clang version 10.0.0 (trunk 367256) (llvm/trunk 367266)"}
96 !14 = distinct !DISubprogram(name: "test", scope: !1, file: !1, line: 7, type: !15, scopeLine: 7, flags: DIFlagPrototyped, isDefinition: true, isOptimized: true, unit: !0, retainedNodes: !27)
97 !15 = !DISubroutineType(types: !16)
99 !17 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !18, size: 64)
100 !18 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "v3", file: !1, line: 3, size: 96, elements: !19)
102 !20 = !DIDerivedType(tag: DW_TAG_member, name: "c", scope: !18, file: !1, line: 3, baseType: !21, size: 8)
103 !21 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char)
104 !22 = !DIDerivedType(tag: DW_TAG_member, name: "d", scope: !18, file: !1, line: 3, baseType: !23, size: 64, offset: 32)
105 !23 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "v2", file: !1, line: 2, size: 64, elements: !24)
107 !25 = !DIDerivedType(tag: DW_TAG_member, name: "c", scope: !23, file: !1, line: 2, baseType: !8, size: 32)
108 !26 = !DIDerivedType(tag: DW_TAG_member, name: "d", scope: !23, file: !1, line: 2, baseType: !8, size: 32, offset: 32)
110 !28 = !DILocalVariable(name: "arg", arg: 1, scope: !14, file: !1, line: 7, type: !17)
111 !29 = !DILocation(line: 0, scope: !14)
112 !30 = !DILocation(line: 8, column: 20, scope: !14)
113 !31 = !DILocation(line: 8, column: 10, scope: !14)
114 !32 = !DILocation(line: 8, column: 3, scope: !14)