[clang][modules] Don't prevent translation of FW_Private includes when explicitly...
[llvm-project.git] / llvm / test / CodeGen / BPF / CORE / anon-union-localvar-pragma.ll
blobd2fee10d27710763c14cb097befdfe14aa1f32da
1 ; RUN: opt -O2 -mtriple=bpf-pc-linux %s | llvm-dis > %t1
2 ; RUN: llc -o - %t1 | FileCheck %s
4 ; Source:
5 ;   #pragma clang attribute push (__attribute__((preserve_access_index)), apply_to = record)
6 ;   typedef union {
7 ;       struct {
8 ;               void    *kernel;
9 ;               void    *user;
10 ;       };
11 ;       unsigned is_kernel : 1;
12 ;   } sockptr_t;
13 ;   #pragma clang attribute pop
14 ;   void *foo(void);
15 ;   int test() {
16 ;     sockptr_t *arg = foo();
17 ;     return __builtin_preserve_field_info(arg->is_kernel, 1);
18 ;   }
19 ; Compilation flag:
20 ;   clang -target bpf -O2 -S -emit-llvm -g -Xclang -disable-llvm-passes test.c
22 %union.sockptr_t = type { %struct.anon }
23 %struct.anon = type { ptr, ptr }
25 ; Function Attrs: nounwind
26 define dso_local i32 @test() #0 !dbg !7 {
27 entry:
28   %arg = alloca ptr, align 8
29   call void @llvm.lifetime.start.p0(i64 8, ptr %arg) #6, !dbg !25
30   call void @llvm.dbg.declare(metadata ptr %arg, metadata !12, metadata !DIExpression()), !dbg !26
31   %call = call ptr @foo(), !dbg !27
32   store ptr %call, ptr %arg, align 8, !dbg !26, !tbaa !28
33   %0 = load ptr, ptr %arg, align 8, !dbg !32, !tbaa !28
34   %1 = call ptr @llvm.preserve.struct.access.index.p0.p0(ptr elementtype(%union.sockptr_t) %0, i32 0, i32 1), !dbg !33, !llvm.preserve.access.index !15
35   %2 = call i32 @llvm.bpf.preserve.field.info.p0(ptr %1, i64 1), !dbg !34
36   call void @llvm.lifetime.end.p0(i64 8, ptr %arg) #6, !dbg !35
37   ret i32 %2, !dbg !36
40 ; CHECK:             .long   56                              # BTF_KIND_TYPEDEF(id = 7)
41 ; CHECK-NEXT:        .long   134217728                       # 0x8000000
42 ; CHECK-NEXT:        .long   8
43 ; CHECK-NEXT:        .long   0                               # BTF_KIND_UNION(id = 8)
45 ; CHECK:             .ascii  ".text"                         # string offset=10
46 ; CHECK:             .ascii  "sockptr_t"                     # string offset=56
47 ; CHECK:             .ascii  "0:1"                           # string offset=101
50 ; CHECK:             .long   16                              # FieldReloc
51 ; CHECK-NEXT:        .long   10                              # Field reloc section string offset=10
52 ; CHECK-NEXT:        .long   1
53 ; CHECK-NEXT:        .long   .Ltmp[[#]]
54 ; CHECK-NEXT:        .long   7
55 ; CHECK-NEXT:        .long   101
56 ; CHECK-NEXT:        .long   1
58 ; Function Attrs: argmemonly nocallback nofree nosync nounwind willreturn
59 declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1
61 ; Function Attrs: nocallback nofree nosync nounwind readnone speculatable willreturn
62 declare void @llvm.dbg.declare(metadata, metadata, metadata) #2
64 declare !dbg !37 dso_local ptr @foo() #3
66 ; Function Attrs: nocallback nofree nosync nounwind readnone willreturn
67 declare ptr @llvm.preserve.struct.access.index.p0.p0(ptr, i32 immarg, i32 immarg) #4
69 ; Function Attrs: nounwind readnone
70 declare i32 @llvm.bpf.preserve.field.info.p0(ptr, i64 immarg) #5
72 ; Function Attrs: argmemonly nocallback nofree nosync nounwind willreturn
73 declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1
75 attributes #0 = { nounwind "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
76 attributes #1 = { argmemonly nocallback nofree nosync nounwind willreturn }
77 attributes #2 = { nocallback nofree nosync nounwind readnone speculatable willreturn }
78 attributes #3 = { "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
79 attributes #4 = { nocallback nofree nosync nounwind readnone willreturn }
80 attributes #5 = { nounwind readnone }
81 attributes #6 = { nounwind }
83 !llvm.dbg.cu = !{!0}
84 !llvm.module.flags = !{!2, !3, !4, !5}
85 !llvm.ident = !{!6}
87 !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 15.0.0 (https://github.com/llvm/llvm-project.git 8c7d5118961e7ffc0304126ec2122d21e2eb1f79)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
88 !1 = !DIFile(filename: "test.c", directory: "/tmp/home/yhs/work/test/anon", checksumkind: CSK_MD5, checksum: "2c5f698241a8b5ddf345a5743dfca258")
89 !2 = !{i32 7, !"Dwarf Version", i32 5}
90 !3 = !{i32 2, !"Debug Info Version", i32 3}
91 !4 = !{i32 1, !"wchar_size", i32 4}
92 !5 = !{i32 7, !"frame-pointer", i32 2}
93 !6 = !{!"clang version 15.0.0 (https://github.com/llvm/llvm-project.git 8c7d5118961e7ffc0304126ec2122d21e2eb1f79)"}
94 !7 = distinct !DISubprogram(name: "test", scope: !1, file: !1, line: 11, type: !8, scopeLine: 11, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !11)
95 !8 = !DISubroutineType(types: !9)
96 !9 = !{!10}
97 !10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
98 !11 = !{!12}
99 !12 = !DILocalVariable(name: "arg", scope: !7, file: !1, line: 12, type: !13)
100 !13 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !14, size: 64)
101 !14 = !DIDerivedType(tag: DW_TAG_typedef, name: "sockptr_t", file: !1, line: 8, baseType: !15)
102 !15 = distinct !DICompositeType(tag: DW_TAG_union_type, file: !1, line: 2, size: 128, elements: !16)
103 !16 = !{!17, !23}
104 !17 = !DIDerivedType(tag: DW_TAG_member, scope: !15, file: !1, line: 3, baseType: !18, size: 128)
105 !18 = distinct !DICompositeType(tag: DW_TAG_structure_type, scope: !15, file: !1, line: 3, size: 128, elements: !19)
106 !19 = !{!20, !22}
107 !20 = !DIDerivedType(tag: DW_TAG_member, name: "kernel", scope: !18, file: !1, line: 4, baseType: !21, size: 64)
108 !21 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: null, size: 64)
109 !22 = !DIDerivedType(tag: DW_TAG_member, name: "user", scope: !18, file: !1, line: 5, baseType: !21, size: 64, offset: 64)
110 !23 = !DIDerivedType(tag: DW_TAG_member, name: "is_kernel", scope: !15, file: !1, line: 7, baseType: !24, size: 1, flags: DIFlagBitField, extraData: i64 0)
111 !24 = !DIBasicType(name: "unsigned int", size: 32, encoding: DW_ATE_unsigned)
112 !25 = !DILocation(line: 12, column: 3, scope: !7)
113 !26 = !DILocation(line: 12, column: 14, scope: !7)
114 !27 = !DILocation(line: 12, column: 20, scope: !7)
115 !28 = !{!29, !29, i64 0}
116 !29 = !{!"any pointer", !30, i64 0}
117 !30 = !{!"omnipotent char", !31, i64 0}
118 !31 = !{!"Simple C/C++ TBAA"}
119 !32 = !DILocation(line: 13, column: 40, scope: !7)
120 !33 = !DILocation(line: 13, column: 45, scope: !7)
121 !34 = !DILocation(line: 13, column: 10, scope: !7)
122 !35 = !DILocation(line: 14, column: 1, scope: !7)
123 !36 = !DILocation(line: 13, column: 3, scope: !7)
124 !37 = !DISubprogram(name: "foo", scope: !1, file: !1, line: 10, type: !38, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized, retainedNodes: !40)
125 !38 = !DISubroutineType(types: !39)
126 !39 = !{!21}
127 !40 = !{}