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