1 ; RUN: opt -O2 -mtriple=bpf-pc-linux %s | llvm-dis > %t1
2 ; RUN: llc -o - %t1 | FileCheck %s
5 ; #pragma clang attribute push (__attribute__((preserve_access_index)), apply_to = record)
11 ; unsigned is_kernel : 1;
13 ; #pragma clang attribute pop
14 ; int test(sockptr_t *arg) {
15 ; return arg->is_kernel;
18 ; clang -target bpf -O2 -S -emit-llvm -g -Xclang -disable-llvm-passes test.c
20 %struct.sockptr_t = type { %union.anon, i8 }
21 %union.anon = type { ptr }
23 ; Function Attrs: nounwind
24 define dso_local i32 @test(ptr noundef %arg) #0 !dbg !7 {
26 %arg.addr = alloca ptr, align 8
27 store ptr %arg, ptr %arg.addr, align 8, !tbaa !25
28 call void @llvm.dbg.declare(metadata ptr %arg.addr, metadata !24, metadata !DIExpression()), !dbg !29
29 %0 = load ptr, ptr %arg.addr, align 8, !dbg !30, !tbaa !25
30 %1 = call ptr @llvm.preserve.struct.access.index.p0.p0(ptr elementtype(%struct.sockptr_t) %0, i32 1, i32 1), !dbg !31, !llvm.preserve.access.index !13
31 %bf.load = load i8, ptr %1, align 8, !dbg !31
32 %bf.clear = and i8 %bf.load, 1, !dbg !31
33 %bf.cast = zext i8 %bf.clear to i32, !dbg !31
34 ret i32 %bf.cast, !dbg !32
37 ; CHECK: .long 1 # BTF_KIND_TYPEDEF(id = 2)
38 ; CHECK-NEXT: .long 134217728 # 0x8000000
40 ; CHECK-NEXT: .long 0 # BTF_KIND_STRUCT(id = 3)
42 ; CHECK: .ascii "sockptr_t" # string offset=1
43 ; CHECK: .ascii ".text" # string offset=59
44 ; CHECK: .ascii "0:1" # string offset=65
46 ; CHECK: .long 16 # FieldReloc
47 ; CHECK-NEXT: .long 59 # Field reloc section string offset=59
49 ; CHECK-NEXT: .long .Ltmp[[#]]
51 ; CHECK-NEXT: .long 65
54 ; Function Attrs: nocallback nofree nosync nounwind readnone speculatable willreturn
55 declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
57 ; Function Attrs: nocallback nofree nosync nounwind readnone willreturn
58 declare ptr @llvm.preserve.struct.access.index.p0.p0(ptr, i32 immarg, i32 immarg) #2
60 attributes #0 = { nounwind "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
61 attributes #1 = { nocallback nofree nosync nounwind readnone speculatable willreturn }
62 attributes #2 = { nocallback nofree nosync nounwind readnone willreturn }
65 !llvm.module.flags = !{!2, !3, !4, !5}
68 !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 15.0.0 (https://github.com/llvm/llvm-project.git d81a8759c969344c1e96992aab30f5b5a9d5ffd3)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
69 !1 = !DIFile(filename: "test.c", directory: "/tmp/home/yhs/work/test/anon", checksumkind: CSK_MD5, checksum: "7ba33bf2146cc86b1c8396f6d3eace81")
70 !2 = !{i32 7, !"Dwarf Version", i32 5}
71 !3 = !{i32 2, !"Debug Info Version", i32 3}
72 !4 = !{i32 1, !"wchar_size", i32 4}
73 !5 = !{i32 7, !"frame-pointer", i32 2}
74 !6 = !{!"clang version 15.0.0 (https://github.com/llvm/llvm-project.git d81a8759c969344c1e96992aab30f5b5a9d5ffd3)"}
75 !7 = distinct !DISubprogram(name: "test", scope: !1, file: !1, line: 10, type: !8, scopeLine: 10, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !23)
76 !8 = !DISubroutineType(types: !9)
78 !10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
79 !11 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !12, size: 64)
80 !12 = !DIDerivedType(tag: DW_TAG_typedef, name: "sockptr_t", file: !1, line: 8, baseType: !13)
81 !13 = distinct !DICompositeType(tag: DW_TAG_structure_type, file: !1, line: 2, size: 128, elements: !14)
83 !15 = !DIDerivedType(tag: DW_TAG_member, scope: !13, file: !1, line: 3, baseType: !16, size: 64)
84 !16 = distinct !DICompositeType(tag: DW_TAG_union_type, scope: !13, file: !1, line: 3, size: 64, elements: !17)
86 !18 = !DIDerivedType(tag: DW_TAG_member, name: "kernel", scope: !16, file: !1, line: 4, baseType: !19, size: 64)
87 !19 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: null, size: 64)
88 !20 = !DIDerivedType(tag: DW_TAG_member, name: "user", scope: !16, file: !1, line: 5, baseType: !19, size: 64)
89 !21 = !DIDerivedType(tag: DW_TAG_member, name: "is_kernel", scope: !13, file: !1, line: 7, baseType: !22, size: 1, offset: 64, flags: DIFlagBitField, extraData: i64 64)
90 !22 = !DIBasicType(name: "unsigned int", size: 32, encoding: DW_ATE_unsigned)
92 !24 = !DILocalVariable(name: "arg", arg: 1, scope: !7, file: !1, line: 10, type: !11)
93 !25 = !{!26, !26, i64 0}
94 !26 = !{!"any pointer", !27, i64 0}
95 !27 = !{!"omnipotent char", !28, i64 0}
96 !28 = !{!"Simple C/C++ TBAA"}
97 !29 = !DILocation(line: 10, column: 21, scope: !7)
98 !30 = !DILocation(line: 11, column: 10, scope: !7)
99 !31 = !DILocation(line: 11, column: 15, scope: !7)
100 !32 = !DILocation(line: 11, column: 3, scope: !7)