brintos

brintos / llvm-project-archived public Read only

0
0
Text · 5.4 KiB · 38b1c99 Raw
111 lines · plain
1; RUN: opt -O2 %s | llvm-dis > %t12; RUN: llc -filetype=asm -o - %t1 | FileCheck -check-prefixes=CHECK %s3; RUN: llc -mattr=+alu32 -filetype=asm -o - %t1 | FileCheck -check-prefixes=CHECK %s4; Source code:5;   struct v1 { int a; int b; };6;   struct v2 { int c; int d; };7;   struct v3 { char c; struct v2 d; };8;   #define _(x) (__builtin_preserve_access_index(x))9;   #define cast_to_v1(x) ((struct v1 *)(x))10;   int get_value(const int *arg);11;   int test(struct v3 *arg) {12;     return get_value(_(&cast_to_v1(&arg->d)->b));13;   }14; Compilation flag:15;   clang -target bpf -O2 -g -S -emit-llvm -Xclang -disable-llvm-passes test.c16 17target triple = "bpf"18 19%struct.v3 = type { i8, %struct.v2 }20%struct.v2 = type { i32, i32 }21%struct.v1 = type { i32, i32 }22 23; Function Attrs: nounwind24define dso_local i32 @test(ptr %arg) local_unnamed_addr !dbg !14 {25entry:26  call void @llvm.dbg.value(metadata ptr %arg, metadata !28, metadata !DIExpression()), !dbg !2927  %0 = tail call ptr @llvm.preserve.struct.access.index.p0.v2s.p0.v3s(ptr elementtype(%struct.v3) %arg, i32 1, i32 1), !dbg !30, !llvm.preserve.access.index !1828  %1 = tail call ptr @llvm.preserve.struct.access.index.p0.p0.v1s(ptr elementtype(%struct.v1) %0, i32 1, i32 1), !dbg !30, !llvm.preserve.access.index !529  %call = tail call i32 @get_value(ptr %1), !dbg !3130  ret i32 %call, !dbg !3231}32 33; CHECK:              r2 = 434; CHECK:              r1 += r235; CHECK:              r2 = 436; CHECK:              r1 += r237; CHECK:              call get_value38 39; CHECK:             .long   1                       # BTF_KIND_STRUCT(id = [[V3_TID:[0-9]+]])40; CHECK:             .long   81                      # BTF_KIND_STRUCT(id = [[V1_TID:[0-9]+]])41 42; CHECK:             .ascii  "v3"                    # string offset=143; CHECK-NEXT:        .byte   044; CHECK:             .ascii  ".text"                 # string offset=[[SEC_STR:[0-9]+]]45; CHECK-NEXT:        .byte   046; CHECK:             .ascii  "0:1"                   # string offset=[[ACCESS_STR:[0-9]+]]47; CHECK-NEXT:        .byte   048; CHECK:             .ascii  "v1"                    # string offset=8149; CHECK-NEXT:        .byte   050 51; CHECK:             .long   16                      # FieldReloc52; CHECK-NEXT:        .long   [[SEC_STR]]             # Field reloc section string offset=[[SEC_STR]]53; CHECK-NEXT:        .long   254; CHECK-NEXT:        .long   .Ltmp{{[0-9]+}}55; CHECK-NEXT:        .long   [[V3_TID]]56; CHECK-NEXT:        .long   [[ACCESS_STR]]57; CHECK-NEXT:        .long   058; CHECK-NEXT:        .long   .Ltmp{{[0-9]+}}59; CHECK-NEXT:        .long   [[V1_TID]]60; CHECK-NEXT:        .long   [[ACCESS_STR]]61; CHECK-NEXT:        .long   062 63declare dso_local i32 @get_value(ptr) local_unnamed_addr64 65; Function Attrs: nounwind readnone66declare ptr @llvm.preserve.struct.access.index.p0.v2s.p0.v3s(ptr, i32, i32)67 68; Function Attrs: nounwind readnone69declare ptr @llvm.preserve.struct.access.index.p0.p0.v1s(ptr, i32, i32)70 71; Function Attrs: nounwind readnone speculatable willreturn72declare void @llvm.dbg.value(metadata, metadata, metadata)73 74!llvm.dbg.cu = !{!0}75!llvm.module.flags = !{!10, !11, !12}76!llvm.ident = !{!13}77 78!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 10.0.0 (trunk 367256) (llvm/trunk 367266)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !3, nameTableKind: None)79!1 = !DIFile(filename: "test.c", directory: "/tmp/home/yhs/work/tests/llvm/cast")80!2 = !{}81!3 = !{!4}82!4 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !5, size: 64)83!5 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "v1", file: !1, line: 1, size: 64, elements: !6)84!6 = !{!7, !9}85!7 = !DIDerivedType(tag: DW_TAG_member, name: "a", scope: !5, file: !1, line: 1, baseType: !8, size: 32)86!8 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)87!9 = !DIDerivedType(tag: DW_TAG_member, name: "b", scope: !5, file: !1, line: 1, baseType: !8, size: 32, offset: 32)88!10 = !{i32 2, !"Dwarf Version", i32 4}89!11 = !{i32 2, !"Debug Info Version", i32 3}90!12 = !{i32 1, !"wchar_size", i32 4}91!13 = !{!"clang version 10.0.0 (trunk 367256) (llvm/trunk 367266)"}92!14 = distinct !DISubprogram(name: "test", scope: !1, file: !1, line: 7, type: !15, scopeLine: 7, flags: DIFlagPrototyped, isDefinition: true, isOptimized: true, unit: !0, retainedNodes: !27)93!15 = !DISubroutineType(types: !16)94!16 = !{!8, !17}95!17 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !18, size: 64)96!18 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "v3", file: !1, line: 3, size: 96, elements: !19)97!19 = !{!20, !22}98!20 = !DIDerivedType(tag: DW_TAG_member, name: "c", scope: !18, file: !1, line: 3, baseType: !21, size: 8)99!21 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char)100!22 = !DIDerivedType(tag: DW_TAG_member, name: "d", scope: !18, file: !1, line: 3, baseType: !23, size: 64, offset: 32)101!23 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "v2", file: !1, line: 2, size: 64, elements: !24)102!24 = !{!25, !26}103!25 = !DIDerivedType(tag: DW_TAG_member, name: "c", scope: !23, file: !1, line: 2, baseType: !8, size: 32)104!26 = !DIDerivedType(tag: DW_TAG_member, name: "d", scope: !23, file: !1, line: 2, baseType: !8, size: 32, offset: 32)105!27 = !{!28}106!28 = !DILocalVariable(name: "arg", arg: 1, scope: !14, file: !1, line: 7, type: !17)107!29 = !DILocation(line: 0, scope: !14)108!30 = !DILocation(line: 8, column: 20, scope: !14)109!31 = !DILocation(line: 8, column: 10, scope: !14)110!32 = !DILocation(line: 8, column: 3, scope: !14)111