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 ; typedef struct s1 { char a1 [5][5]; } __s1;
5 ; union u1 { int b1; __s1 b2; };
6 ; enum { FIELD_RSHIFT_U64 = 5, };
7 ; int test(union u1 *arg) {
8 ; unsigned r1 = __builtin_preserve_field_info(arg->b2.a1[3], FIELD_RSHIFT_U64);
9 ; unsigned r2 = __builtin_preserve_field_info(arg->b2.a1[3][3], FIELD_RSHIFT_U64);
10 ; /* r1 : 24, r2 : 56 */
14 ; clang -target bpf -O2 -g -S -emit-llvm test.c
16 %union.u1 = type { i32, [24 x i8] }
17 %struct.s1 = type { [5 x [5 x i8]] }
19 ; Function Attrs: nounwind readnone
20 define dso_local i32 @test(%union.u1* %arg) local_unnamed_addr #0 !dbg !18 {
22 call void @llvm.dbg.value(metadata %union.u1* %arg, metadata !32, metadata !DIExpression()), !dbg !35
23 %0 = tail call %union.u1* @llvm.preserve.union.access.index.p0s_union.u1s.p0s_union.u1s(%union.u1* %arg, i32 1), !dbg !36, !llvm.preserve.access.index !23
24 %b2 = bitcast %union.u1* %0 to %struct.s1*, !dbg !36
25 %1 = tail call [5 x [5 x i8]]* @llvm.preserve.struct.access.index.p0a5a5i8.p0s_struct.s1s(%struct.s1* %b2, i32 0, i32 0), !dbg !37, !llvm.preserve.access.index !28
26 %2 = tail call [5 x i8]* @llvm.preserve.array.access.index.p0a5i8.p0a5a5i8([5 x [5 x i8]]* %1, i32 1, i32 3), !dbg !38, !llvm.preserve.access.index !8
27 %3 = tail call i32 @llvm.bpf.preserve.field.info.p0a5i8([5 x i8]* %2, i64 5), !dbg !39
28 call void @llvm.dbg.value(metadata i32 %3, metadata !33, metadata !DIExpression()), !dbg !35
29 %4 = tail call i8* @llvm.preserve.array.access.index.p0i8.p0a5i8([5 x i8]* %2, i32 1, i32 3), !dbg !40, !llvm.preserve.access.index !12
30 %5 = tail call i32 @llvm.bpf.preserve.field.info.p0i8(i8* %4, i64 5), !dbg !41
31 call void @llvm.dbg.value(metadata i32 %5, metadata !34, metadata !DIExpression()), !dbg !35
32 %add = add i32 %5, %3, !dbg !42
33 ret i32 %add, !dbg !43
41 ; CHECK: .long 1 # BTF_KIND_UNION(id = 2)
42 ; CHECK: .ascii "u1" # string offset=1
43 ; CHECK: .ascii ".text" # string offset=59
44 ; CHECK: .ascii "0:1:0:3" # string offset=65
45 ; CHECK: .ascii "0:1:0:3:3" # string offset=110
47 ; CHECK: .long 16 # FieldReloc
48 ; CHECK-NEXT: .long 59 # Field reloc section string offset=59
50 ; CHECK-NEXT: .long .Ltmp{{[0-9]+}}
52 ; CHECK-NEXT: .long 65
54 ; CHECK-NEXT: .long .Ltmp{{[0-9]+}}
56 ; CHECK-NEXT: .long 110
59 ; Function Attrs: nounwind readnone
60 declare %union.u1* @llvm.preserve.union.access.index.p0s_union.u1s.p0s_union.u1s(%union.u1*, i32) #1
62 ; Function Attrs: nounwind readnone
63 declare [5 x [5 x i8]]* @llvm.preserve.struct.access.index.p0a5a5i8.p0s_struct.s1s(%struct.s1*, i32, i32) #1
65 ; Function Attrs: nounwind readnone
66 declare [5 x i8]* @llvm.preserve.array.access.index.p0a5i8.p0a5a5i8([5 x [5 x i8]]*, i32, i32) #1
68 ; Function Attrs: nounwind readnone
69 declare i32 @llvm.bpf.preserve.field.info.p0a5i8([5 x i8]*, i64) #1
71 ; Function Attrs: nounwind readnone
72 declare i8* @llvm.preserve.array.access.index.p0i8.p0a5i8([5 x i8]*, i32, i32) #1
74 ; Function Attrs: nounwind readnone
75 declare i32 @llvm.bpf.preserve.field.info.p0i8(i8*, i64) #1
77 ; Function Attrs: nounwind readnone speculatable willreturn
78 declare void @llvm.dbg.value(metadata, metadata, metadata) #2
80 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" }
81 attributes #1 = { nounwind readnone }
82 attributes #2 = { nounwind readnone speculatable willreturn }
85 !llvm.module.flags = !{!14, !15, !16}
88 !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: !7, nameTableKind: None)
89 !1 = !DIFile(filename: "test.c", directory: "/tmp/home/yhs/work/tests/core")
91 !3 = !DICompositeType(tag: DW_TAG_enumeration_type, file: !1, line: 3, baseType: !4, size: 32, elements: !5)
92 !4 = !DIBasicType(name: "unsigned int", size: 32, encoding: DW_ATE_unsigned)
94 !6 = !DIEnumerator(name: "FIELD_RSHIFT_U64", value: 5, isUnsigned: true)
96 !8 = !DICompositeType(tag: DW_TAG_array_type, baseType: !9, size: 200, elements: !10)
97 !9 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char)
99 !11 = !DISubrange(count: 5)
100 !12 = !DICompositeType(tag: DW_TAG_array_type, baseType: !9, size: 40, elements: !13)
102 !14 = !{i32 2, !"Dwarf Version", i32 4}
103 !15 = !{i32 2, !"Debug Info Version", i32 3}
104 !16 = !{i32 1, !"wchar_size", i32 4}
105 !17 = !{!"clang version 10.0.0 (https://github.com/llvm/llvm-project.git c1e02f16f1105ffaf1c35ee8bc38b7d6db5c6ea9)"}
106 !18 = distinct !DISubprogram(name: "test", scope: !1, file: !1, line: 4, type: !19, scopeLine: 4, flags: DIFlagPrototyped, isDefinition: true, isOptimized: true, unit: !0, retainedNodes: !31)
107 !19 = !DISubroutineType(types: !20)
109 !21 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
110 !22 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !23, size: 64)
111 !23 = distinct !DICompositeType(tag: DW_TAG_union_type, name: "u1", file: !1, line: 2, size: 224, elements: !24)
113 !25 = !DIDerivedType(tag: DW_TAG_member, name: "b1", scope: !23, file: !1, line: 2, baseType: !21, size: 32)
114 !26 = !DIDerivedType(tag: DW_TAG_member, name: "b2", scope: !23, file: !1, line: 2, baseType: !27, size: 200)
115 !27 = !DIDerivedType(tag: DW_TAG_typedef, name: "__s1", file: !1, line: 1, baseType: !28)
116 !28 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "s1", file: !1, line: 1, size: 200, elements: !29)
118 !30 = !DIDerivedType(tag: DW_TAG_member, name: "a1", scope: !28, file: !1, line: 1, baseType: !8, size: 200)
119 !31 = !{!32, !33, !34}
120 !32 = !DILocalVariable(name: "arg", arg: 1, scope: !18, file: !1, line: 4, type: !22)
121 !33 = !DILocalVariable(name: "r1", scope: !18, file: !1, line: 5, type: !4)
122 !34 = !DILocalVariable(name: "r2", scope: !18, file: !1, line: 6, type: !4)
123 !35 = !DILocation(line: 0, scope: !18)
124 !36 = !DILocation(line: 5, column: 52, scope: !18)
125 !37 = !DILocation(line: 5, column: 55, scope: !18)
126 !38 = !DILocation(line: 5, column: 47, scope: !18)
127 !39 = !DILocation(line: 5, column: 17, scope: !18)
128 !40 = !DILocation(line: 6, column: 47, scope: !18)
129 !41 = !DILocation(line: 6, column: 17, scope: !18)
130 !42 = !DILocation(line: 8, column: 13, scope: !18)
131 !43 = !DILocation(line: 8, column: 3, scope: !18)