xref: /llvm-project/llvm/test/CodeGen/BPF/CORE/anon-struct-argument-pragma.ll (revision 6e6c1efe04d45b717091e06eec94f0eef64839b1)
1; RUN: opt -O2 -mtriple=bpf-pc-linux %s | llvm-dis > %t1
2; RUN: llc -o - %t1 | FileCheck %s
3;
4; Source:
5;   #pragma clang attribute push (__attribute__((preserve_access_index)), apply_to = record)
6;   typedef struct {
7;       union {
8;               void	*kernel;
9;               void	*user;
10;       };
11;       unsigned is_kernel : 1;
12;   } sockptr_t;
13;   #pragma clang attribute pop
14;   int test(sockptr_t *arg) {
15;     return arg->is_kernel;
16;   }
17; Compilation flag:
18;   clang -target bpf -O2 -S -emit-llvm -g -Xclang -disable-llvm-passes test.c
19
20%struct.sockptr_t = type { %union.anon, i8 }
21%union.anon = type { ptr }
22
23; Function Attrs: nounwind
24define dso_local i32 @test(ptr noundef %arg) #0 !dbg !7 {
25entry:
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
35}
36
37; CHECK:             .long   1                               # BTF_KIND_TYPEDEF(id = 2)
38; CHECK-NEXT:        .long   134217728                       # 0x8000000
39; CHECK-NEXT:        .long   3
40; CHECK-NEXT:        .long   0                               # BTF_KIND_STRUCT(id = 3)
41
42; CHECK:             .ascii  "sockptr_t"                     # string offset=1
43; CHECK:             .ascii  ".text"                         # string offset=59
44; CHECK:             .ascii  "0:1"                           # string offset=65
45
46; CHECK:             .long   16                              # FieldReloc
47; CHECK-NEXT:        .long   59                              # Field reloc section string offset=59
48; CHECK-NEXT:        .long   1
49; CHECK-NEXT:        .long   .Ltmp[[#]]
50; CHECK-NEXT:        .long   2
51; CHECK-NEXT:        .long   65
52; CHECK-NEXT:        .long   0
53
54; Function Attrs: nocallback nofree nosync nounwind readnone speculatable willreturn
55declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
56
57; Function Attrs: nocallback nofree nosync nounwind readnone willreturn
58declare ptr @llvm.preserve.struct.access.index.p0.p0(ptr, i32 immarg, i32 immarg) #2
59
60attributes #0 = { nounwind "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
61attributes #1 = { nocallback nofree nosync nounwind readnone speculatable willreturn }
62attributes #2 = { nocallback nofree nosync nounwind readnone willreturn }
63
64!llvm.dbg.cu = !{!0}
65!llvm.module.flags = !{!2, !3, !4, !5}
66!llvm.ident = !{!6}
67
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)
77!9 = !{!10, !11}
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)
82!14 = !{!15, !21}
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)
85!17 = !{!18, !20}
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)
91!23 = !{!24}
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)
101