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
5 ; union v1 { int a; int b; };
6 ; typedef union v1 __v1;
8 ; union v3 { char c; __int d[40]; };
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[4])->b));
17 ; clang -target bpf -O2 -g -S -emit-llvm -Xclang -disable-llvm-passes test.c
21 %union.v3 = type { [40 x i32] }
22 %union.v1 = type { i32 }
24 ; Function Attrs: nounwind
25 define dso_local i32 @test(%union.v3* %arg) local_unnamed_addr #0 !dbg !19 {
27 call void @llvm.dbg.value(metadata %union.v3* %arg, metadata !30, metadata !DIExpression()), !dbg !31
28 %0 = tail call %union.v3* @llvm.preserve.union.access.index.p0s_union.v3s.p0s_union.v3s(%union.v3* %arg, i32 1), !dbg !32, !llvm.preserve.access.index !24
29 %d = getelementptr inbounds %union.v3, %union.v3* %0, i64 0, i32 0, !dbg !32
30 %1 = tail call i32* @llvm.preserve.array.access.index.p0i32.p0a40i32([40 x i32]* elementtype([40 x i32]) %d, i32 1, i32 4), !dbg !32, !llvm.preserve.access.index !11
31 %2 = bitcast i32* %1 to %union.v1*, !dbg !32
32 %3 = tail call %union.v1* @llvm.preserve.union.access.index.p0s_union.v1s.p0s_union.v1s(%union.v1* %2, i32 1), !dbg !32, !llvm.preserve.access.index !6
33 %b = getelementptr inbounds %union.v1, %union.v1* %3, i64 0, i32 0, !dbg !32
34 %call = tail call i32 @get_value(i32* %b) #4, !dbg !33
35 ret i32 %call, !dbg !34
42 ; CHECK: call get_value
44 ; CHECK: .long 6 # BTF_KIND_UNION(id = [[TID1:[0-9]+]])
45 ; CHECK: .long 111 # BTF_KIND_UNION(id = [[TID2:[0-9]+]])
47 ; CHECK: .ascii "v3" # string offset=6
48 ; CHECK: .ascii ".text" # string offset=57
49 ; CHECK: .ascii "0:1:4" # string offset=63
50 ; CHECK: .ascii "v1" # string offset=111
51 ; CHECK: .ascii "0:1" # string offset=118
53 ; CHECK: .long 16 # FieldReloc
54 ; CHECK-NEXT: .long 57 # Field reloc section string offset=57
56 ; CHECK-NEXT: .long .Ltmp{{[0-9]+}}
57 ; CHECK-NEXT: .long [[TID1]]
58 ; CHECK-NEXT: .long 63
60 ; CHECK-NEXT: .long .Ltmp{{[0-9]+}}
61 ; CHECK-NEXT: .long [[TID2]]
62 ; CHECK-NEXT: .long 118
65 declare dso_local i32 @get_value(i32*) local_unnamed_addr #1
67 ; Function Attrs: nounwind readnone
68 declare %union.v3* @llvm.preserve.union.access.index.p0s_union.v3s.p0s_union.v3s(%union.v3*, i32) #2
70 ; Function Attrs: nounwind readnone
71 declare i32* @llvm.preserve.array.access.index.p0i32.p0a40i32([40 x i32]*, i32, i32) #2
73 ; Function Attrs: nounwind readnone
74 declare %union.v1* @llvm.preserve.union.access.index.p0s_union.v1s.p0s_union.v1s(%union.v1*, i32) #2
76 ; Function Attrs: nounwind readnone speculatable willreturn
77 declare void @llvm.dbg.value(metadata, metadata, metadata) #3
79 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" }
80 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" }
81 attributes #2 = { nounwind readnone }
82 attributes #3 = { nounwind readnone speculatable willreturn }
83 attributes #4 = { nounwind }
86 !llvm.module.flags = !{!15, !16, !17}
89 !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)
90 !1 = !DIFile(filename: "test.c", directory: "/tmp/home/yhs/work/tests/llvm/cast")
93 !4 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !5, size: 64)
94 !5 = !DIDerivedType(tag: DW_TAG_typedef, name: "__v1", file: !1, line: 2, baseType: !6)
95 !6 = distinct !DICompositeType(tag: DW_TAG_union_type, name: "v1", file: !1, line: 1, size: 32, elements: !7)
97 !8 = !DIDerivedType(tag: DW_TAG_member, name: "a", scope: !6, file: !1, line: 1, baseType: !9, size: 32)
98 !9 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
99 !10 = !DIDerivedType(tag: DW_TAG_member, name: "b", scope: !6, file: !1, line: 1, baseType: !9, size: 32)
100 !11 = !DICompositeType(tag: DW_TAG_array_type, baseType: !12, size: 1280, elements: !13)
101 !12 = !DIDerivedType(tag: DW_TAG_typedef, name: "__int", file: !1, line: 3, baseType: !9)
103 !14 = !DISubrange(count: 40)
104 !15 = !{i32 2, !"Dwarf Version", i32 4}
105 !16 = !{i32 2, !"Debug Info Version", i32 3}
106 !17 = !{i32 1, !"wchar_size", i32 4}
107 !18 = !{!"clang version 10.0.0 (trunk 367256) (llvm/trunk 367266)"}
108 !19 = distinct !DISubprogram(name: "test", scope: !1, file: !1, line: 9, type: !20, scopeLine: 9, flags: DIFlagPrototyped, isDefinition: true, isOptimized: true, unit: !0, retainedNodes: !29)
109 !20 = !DISubroutineType(types: !21)
111 !22 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !23, size: 64)
112 !23 = !DIDerivedType(tag: DW_TAG_typedef, name: "__v3", file: !1, line: 5, baseType: !24)
113 !24 = distinct !DICompositeType(tag: DW_TAG_union_type, name: "v3", file: !1, line: 4, size: 1280, elements: !25)
115 !26 = !DIDerivedType(tag: DW_TAG_member, name: "c", scope: !24, file: !1, line: 4, baseType: !27, size: 8)
116 !27 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char)
117 !28 = !DIDerivedType(tag: DW_TAG_member, name: "d", scope: !24, file: !1, line: 4, baseType: !11, size: 1280)
119 !30 = !DILocalVariable(name: "arg", arg: 1, scope: !19, file: !1, line: 9, type: !22)
120 !31 = !DILocation(line: 0, scope: !19)
121 !32 = !DILocation(line: 10, column: 20, scope: !19)
122 !33 = !DILocation(line: 10, column: 10, scope: !19)
123 !34 = !DILocation(line: 10, column: 3, scope: !19)