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 ; enum A { AA = -1, AB = 0, };
5 ; enum B { BA = 0, BB = 1, };
8 ; typedef struct s1 { __A a1[10]; __B a2[10][10]; } __s1;
9 ; union u1 { int b1; __s1 b2; };
10 ; enum { FIELD_SIGNEDNESS = 3, };
11 ; int test(union u1 *arg) {
12 ; unsigned r1 = __builtin_preserve_field_info(arg->b2.a1[5], FIELD_SIGNEDNESS);
13 ; unsigned r2 = __builtin_preserve_field_info(arg->b2.a2[5][5], FIELD_SIGNEDNESS);
14 ; /* r1 : 1, r2 : 0 */
18 ; clang -target bpf -O2 -g -S -emit-llvm test.c
20 %union.u1 = type { %struct.s1 }
21 %struct.s1 = type { [10 x i32], [10 x [10 x i32]] }
23 ; Function Attrs: nounwind readnone
24 define dso_local i32 @test(%union.u1* %arg) local_unnamed_addr #0 !dbg !29 {
26 call void @llvm.dbg.value(metadata %union.u1* %arg, metadata !43, metadata !DIExpression()), !dbg !46
27 %0 = tail call %union.u1* @llvm.preserve.union.access.index.p0s_union.u1s.p0s_union.u1s(%union.u1* %arg, i32 1), !dbg !47, !llvm.preserve.access.index !33
28 %b2 = getelementptr inbounds %union.u1, %union.u1* %0, i64 0, i32 0, !dbg !47
29 %1 = tail call [10 x i32]* @llvm.preserve.struct.access.index.p0a10i32.p0s_struct.s1s(%struct.s1* %b2, i32 0, i32 0), !dbg !48, !llvm.preserve.access.index !38
30 %2 = tail call i32* @llvm.preserve.array.access.index.p0i32.p0a10i32([10 x i32]* %1, i32 1, i32 5), !dbg !49, !llvm.preserve.access.index !17
31 %3 = tail call i32 @llvm.bpf.preserve.field.info.p0i32(i32* %2, i64 3), !dbg !50
32 call void @llvm.dbg.value(metadata i32 %3, metadata !44, metadata !DIExpression()), !dbg !46
33 %4 = tail call [10 x [10 x i32]]* @llvm.preserve.struct.access.index.p0a10a10i32.p0s_struct.s1s(%struct.s1* %b2, i32 1, i32 1), !dbg !51, !llvm.preserve.access.index !38
34 %5 = tail call [10 x i32]* @llvm.preserve.array.access.index.p0a10i32.p0a10a10i32([10 x [10 x i32]]* %4, i32 1, i32 5), !dbg !52, !llvm.preserve.access.index !21
35 %6 = tail call i32* @llvm.preserve.array.access.index.p0i32.p0a10i32([10 x i32]* %5, i32 1, i32 5), !dbg !52, !llvm.preserve.access.index !24
36 %7 = tail call i32 @llvm.bpf.preserve.field.info.p0i32(i32* %6, i64 3), !dbg !53
37 call void @llvm.dbg.value(metadata i32 %7, metadata !45, metadata !DIExpression()), !dbg !46
38 %add = add i32 %7, %3, !dbg !54
39 ret i32 %add, !dbg !55
47 ; CHECK: .long 1 # BTF_KIND_UNION(id = 2)
48 ; CHECK: .ascii "u1" # string offset=1
49 ; CHECK: .ascii ".text" # string offset=81
50 ; CHECK: .ascii "0:1:0:5" # string offset=87
51 ; CHECK: .ascii "0:1:1:5:5" # string offset=132
53 ; CHECK: .long 16 # FieldReloc
54 ; CHECK-NEXT: .long 81 # Field reloc section string offset=81
56 ; CHECK-NEXT: .long .Ltmp{{[0-9]+}}
58 ; CHECK-NEXT: .long 87
60 ; CHECK-NEXT: .long .Ltmp{{[0-9]+}}
62 ; CHECK-NEXT: .long 132
65 ; Function Attrs: nounwind readnone
66 declare %union.u1* @llvm.preserve.union.access.index.p0s_union.u1s.p0s_union.u1s(%union.u1*, i32) #1
68 ; Function Attrs: nounwind readnone
69 declare [10 x i32]* @llvm.preserve.struct.access.index.p0a10i32.p0s_struct.s1s(%struct.s1*, i32, i32) #1
71 ; Function Attrs: nounwind readnone
72 declare i32* @llvm.preserve.array.access.index.p0i32.p0a10i32([10 x i32]*, i32, i32) #1
74 ; Function Attrs: nounwind readnone
75 declare i32 @llvm.bpf.preserve.field.info.p0i32(i32*, i64) #1
77 ; Function Attrs: nounwind readnone
78 declare [10 x [10 x i32]]* @llvm.preserve.struct.access.index.p0a10a10i32.p0s_struct.s1s(%struct.s1*, i32, i32) #1
80 ; Function Attrs: nounwind readnone
81 declare [10 x i32]* @llvm.preserve.array.access.index.p0a10i32.p0a10a10i32([10 x [10 x i32]]*, i32, i32) #1
83 ; Function Attrs: nounwind readnone speculatable willreturn
84 declare void @llvm.dbg.value(metadata, metadata, metadata) #2
86 attributes #0 = { nounwind readnone "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" }
87 attributes #1 = { nounwind readnone }
88 attributes #2 = { nounwind readnone speculatable willreturn }
91 !llvm.module.flags = !{!25, !26, !27}
94 !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 10.0.0 (https://github.com/llvm/llvm-project.git c1e02f16f1105ffaf1c35ee8bc38b7d6db5c6ea9)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !16, nameTableKind: None)
95 !1 = !DIFile(filename: "test.c", directory: "/tmp/home/yhs/work/tests/core")
97 !3 = !DICompositeType(tag: DW_TAG_enumeration_type, name: "A", file: !1, line: 1, baseType: !4, size: 32, elements: !5)
98 !4 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
100 !6 = !DIEnumerator(name: "AA", value: -1)
101 !7 = !DIEnumerator(name: "AB", value: 0)
102 !8 = !DICompositeType(tag: DW_TAG_enumeration_type, name: "B", file: !1, line: 2, baseType: !9, size: 32, elements: !10)
103 !9 = !DIBasicType(name: "unsigned int", size: 32, encoding: DW_ATE_unsigned)
105 !11 = !DIEnumerator(name: "BA", value: 0, isUnsigned: true)
106 !12 = !DIEnumerator(name: "BB", value: 1, isUnsigned: true)
107 !13 = !DICompositeType(tag: DW_TAG_enumeration_type, file: !1, line: 7, baseType: !9, size: 32, elements: !14)
109 !15 = !DIEnumerator(name: "FIELD_SIGNEDNESS", value: 3, isUnsigned: true)
110 !16 = !{!17, !21, !24}
111 !17 = !DICompositeType(tag: DW_TAG_array_type, baseType: !18, size: 320, elements: !19)
112 !18 = !DIDerivedType(tag: DW_TAG_typedef, name: "__A", file: !1, line: 3, baseType: !3)
114 !20 = !DISubrange(count: 10)
115 !21 = !DICompositeType(tag: DW_TAG_array_type, baseType: !22, size: 3200, elements: !23)
116 !22 = !DIDerivedType(tag: DW_TAG_typedef, name: "__B", file: !1, line: 4, baseType: !8)
118 !24 = !DICompositeType(tag: DW_TAG_array_type, baseType: !22, size: 320, elements: !19)
119 !25 = !{i32 2, !"Dwarf Version", i32 4}
120 !26 = !{i32 2, !"Debug Info Version", i32 3}
121 !27 = !{i32 1, !"wchar_size", i32 4}
122 !28 = !{!"clang version 10.0.0 (https://github.com/llvm/llvm-project.git c1e02f16f1105ffaf1c35ee8bc38b7d6db5c6ea9)"}
123 !29 = distinct !DISubprogram(name: "test", scope: !1, file: !1, line: 8, type: !30, scopeLine: 8, flags: DIFlagPrototyped, isDefinition: true, isOptimized: true, unit: !0, retainedNodes: !42)
124 !30 = !DISubroutineType(types: !31)
126 !32 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !33, size: 64)
127 !33 = distinct !DICompositeType(tag: DW_TAG_union_type, name: "u1", file: !1, line: 6, size: 3520, elements: !34)
129 !35 = !DIDerivedType(tag: DW_TAG_member, name: "b1", scope: !33, file: !1, line: 6, baseType: !4, size: 32)
130 !36 = !DIDerivedType(tag: DW_TAG_member, name: "b2", scope: !33, file: !1, line: 6, baseType: !37, size: 3520)
131 !37 = !DIDerivedType(tag: DW_TAG_typedef, name: "__s1", file: !1, line: 5, baseType: !38)
132 !38 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "s1", file: !1, line: 5, size: 3520, elements: !39)
134 !40 = !DIDerivedType(tag: DW_TAG_member, name: "a1", scope: !38, file: !1, line: 5, baseType: !17, size: 320)
135 !41 = !DIDerivedType(tag: DW_TAG_member, name: "a2", scope: !38, file: !1, line: 5, baseType: !21, size: 3200, offset: 320)
136 !42 = !{!43, !44, !45}
137 !43 = !DILocalVariable(name: "arg", arg: 1, scope: !29, file: !1, line: 8, type: !32)
138 !44 = !DILocalVariable(name: "r1", scope: !29, file: !1, line: 9, type: !9)
139 !45 = !DILocalVariable(name: "r2", scope: !29, file: !1, line: 10, type: !9)
140 !46 = !DILocation(line: 0, scope: !29)
141 !47 = !DILocation(line: 9, column: 52, scope: !29)
142 !48 = !DILocation(line: 9, column: 55, scope: !29)
143 !49 = !DILocation(line: 9, column: 47, scope: !29)
144 !50 = !DILocation(line: 9, column: 17, scope: !29)
145 !51 = !DILocation(line: 10, column: 55, scope: !29)
146 !52 = !DILocation(line: 10, column: 47, scope: !29)
147 !53 = !DILocation(line: 10, column: 17, scope: !29)
148 !54 = !DILocation(line: 12, column: 13, scope: !29)
149 !55 = !DILocation(line: 12, column: 3, scope: !29)