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 ; union v1 { int a; int b; };
5 ; typedef union v1 __v1;
6 ; union v2 { int c; int d; };
7 ; typedef union v2 __v2;
8 ; union v3 { char c; volatile const __v2 d; };
9 ; typedef union v3 __v3;
10 ; #define _(x) (__builtin_preserve_access_index(x))
11 ; #define cast_to_v1(x) ((__v1 *)(x))
12 ; int get_value(const int *arg);
13 ; int test(__v3 *arg) {
14 ; return get_value(_(&cast_to_v1(&arg->d)->b));
17 ; clang -target bpf -O2 -g -S -emit-llvm test.c
19 %union.v3 = type { %union.v2 }
20 %union.v2 = type { i32 }
21 %union.v1 = type { i32 }
23 ; Function Attrs: nounwind
24 define dso_local i32 @test(%union.v3* %arg) local_unnamed_addr #0 !dbg !15 {
26 call void @llvm.dbg.value(metadata %union.v3* %arg, metadata !33, metadata !DIExpression()), !dbg !34
27 %0 = tail call %union.v3* @llvm.preserve.union.access.index.p0s_union.v3s.p0s_union.v3s(%union.v3* %arg, i32 1), !dbg !35, !llvm.preserve.access.index !20
28 %1 = bitcast %union.v3* %0 to %union.v1*, !dbg !35
29 %2 = tail call %union.v1* @llvm.preserve.union.access.index.p0s_union.v1s.p0s_union.v1s(%union.v1* %1, i32 1), !dbg !35, !llvm.preserve.access.index !6
30 %b = getelementptr inbounds %union.v1, %union.v1* %2, i64 0, i32 0, !dbg !35
31 %call = tail call i32 @get_value(i32* %b) #4, !dbg !36
32 ret i32 %call, !dbg !37
39 ; CHECK: call get_value
41 ; CHECK: .long 6 # BTF_KIND_UNION(id = [[TID1:[0-9]+]])
42 ; CHECK: .long 91 # BTF_KIND_UNION(id = [[TID2:[0-9]+]])
44 ; CHECK: .ascii "v3" # string offset=6
45 ; CHECK: .ascii ".text" # string offset=39
46 ; CHECK: .ascii "0:1" # string offset=45
47 ; CHECK: .ascii "v1" # string offset=91
49 ; CHECK: .long 16 # FieldReloc
50 ; CHECK-NEXT: .long 39 # Field reloc section string offset=39
52 ; CHECK-NEXT: .long .Ltmp{{[0-9]+}}
53 ; CHECK-NEXT: .long [[TID1]]
54 ; CHECK-NEXT: .long 45
56 ; CHECK-NEXT: .long .Ltmp{{[0-9]+}}
57 ; CHECK-NEXT: .long [[TID2]]
58 ; CHECK-NEXT: .long 45
61 declare dso_local i32 @get_value(i32*) local_unnamed_addr #1
63 ; Function Attrs: nounwind readnone
64 declare %union.v3* @llvm.preserve.union.access.index.p0s_union.v3s.p0s_union.v3s(%union.v3*, i32) #2
66 ; Function Attrs: nounwind readnone
67 declare %union.v1* @llvm.preserve.union.access.index.p0s_union.v1s.p0s_union.v1s(%union.v1*, 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 = !{!11, !12, !13}
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 = !DIDerivedType(tag: DW_TAG_typedef, name: "__v1", file: !1, line: 2, baseType: !6)
88 !6 = distinct !DICompositeType(tag: DW_TAG_union_type, name: "v1", file: !1, line: 1, size: 32, elements: !7)
90 !8 = !DIDerivedType(tag: DW_TAG_member, name: "a", scope: !6, file: !1, line: 1, baseType: !9, size: 32)
91 !9 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
92 !10 = !DIDerivedType(tag: DW_TAG_member, name: "b", scope: !6, file: !1, line: 1, baseType: !9, size: 32)
93 !11 = !{i32 2, !"Dwarf Version", i32 4}
94 !12 = !{i32 2, !"Debug Info Version", i32 3}
95 !13 = !{i32 1, !"wchar_size", i32 4}
96 !14 = !{!"clang version 10.0.0 (trunk 367256) (llvm/trunk 367266)"}
97 !15 = distinct !DISubprogram(name: "test", scope: !1, file: !1, line: 10, type: !16, scopeLine: 10, flags: DIFlagPrototyped, isDefinition: true, isOptimized: true, unit: !0, retainedNodes: !32)
98 !16 = !DISubroutineType(types: !17)
100 !18 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !19, size: 64)
101 !19 = !DIDerivedType(tag: DW_TAG_typedef, name: "__v3", file: !1, line: 6, baseType: !20)
102 !20 = distinct !DICompositeType(tag: DW_TAG_union_type, name: "v3", file: !1, line: 5, size: 32, elements: !21)
104 !22 = !DIDerivedType(tag: DW_TAG_member, name: "c", scope: !20, file: !1, line: 5, baseType: !23, size: 8)
105 !23 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char)
106 !24 = !DIDerivedType(tag: DW_TAG_member, name: "d", scope: !20, file: !1, line: 5, baseType: !25, size: 32)
107 !25 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !26)
108 !26 = !DIDerivedType(tag: DW_TAG_volatile_type, baseType: !27)
109 !27 = !DIDerivedType(tag: DW_TAG_typedef, name: "__v2", file: !1, line: 4, baseType: !28)
110 !28 = distinct !DICompositeType(tag: DW_TAG_union_type, name: "v2", file: !1, line: 3, size: 32, elements: !29)
112 !30 = !DIDerivedType(tag: DW_TAG_member, name: "c", scope: !28, file: !1, line: 3, baseType: !9, size: 32)
113 !31 = !DIDerivedType(tag: DW_TAG_member, name: "d", scope: !28, file: !1, line: 3, baseType: !9, size: 32)
115 !33 = !DILocalVariable(name: "arg", arg: 1, scope: !15, file: !1, line: 10, type: !18)
116 !34 = !DILocation(line: 0, scope: !15)
117 !35 = !DILocation(line: 11, column: 20, scope: !15)
118 !36 = !DILocation(line: 11, column: 10, scope: !15)
119 !37 = !DILocation(line: 11, column: 3, scope: !15)