Home | History | Annotate | Download | only in Mem2Reg
      1 ; RUN: opt < %s -mem2reg -S | FileCheck %s
      2 
      3 ; Testing conversion from dbg.declare to dbg.value when the variable is a VLA.
      4 ;
      5 ; We can't derive the size of the variable simply by looking at the
      6 ; metadata. But we can find out the size by examining the alloca, so we should
      7 ; know that the load/store instructions are referencing the whole variable,
      8 ; and we expect to get dbg.value intrinsics that maps %entryN (aka %[[PHI]])
      9 ; and %t0 to the variable allocated as %vla1.
     10 
     11 ; ModuleID = 'debug-alloca-vla.ll'
     12 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
     13 target triple = "x86_64-apple-macosx10.12.0"
     14 
     15 ; Function Attrs: nounwind ssp uwtable
     16 define void @scan() #0 !dbg !4 {
     17 entry:
     18   %vla1 = alloca i32, i32 1, align 8
     19   call void @llvm.dbg.declare(metadata i32* %vla1, metadata !10, metadata !DIExpression()), !dbg !18
     20   br label %for.cond, !dbg !18
     21 
     22 for.cond:                                         ; preds = %for.cond, %entry
     23 ; CHECK: %[[PHI:.*]] = phi i32 [ undef, %entry ], [ %t0, %for.cond ]
     24   %entryN = load i32, i32* %vla1, align 8, !dbg !18
     25 ; CHECK: call void @llvm.dbg.value(metadata i32 %[[PHI]],
     26 ; CHECK-SAME:                      metadata !DIExpression())
     27   %t0 = add i32 %entryN, 1
     28 ; CHECK: %t0 = add i32 %[[PHI]], 1
     29 ; CHECK: call void @llvm.dbg.value(metadata i32 %t0,
     30 ; CHECK-SAME:                      metadata !DIExpression())
     31  store i32 %t0, i32* %vla1, align 8, !dbg !18
     32   br label %for.cond, !dbg !18
     33 }
     34 
     35 ; Function Attrs: nounwind readnone speculatable
     36 declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
     37 
     38 attributes #0 = { nounwind ssp uwtable }
     39 attributes #1 = { nounwind readnone speculatable }
     40 
     41 !llvm.dbg.cu = !{!0}
     42 !llvm.module.flags = !{!2, !3}
     43 
     44 !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "adrian", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug)
     45 !1 = !DIFile(filename: "<stdin>", directory: "/")
     46 !2 = !{i32 2, !"Debug Info Version", i32 3}
     47 !3 = !{i32 7, !"PIC Level", i32 2}
     48 !4 = distinct !DISubprogram(name: "scan", scope: !1, file: !1, line: 4, type: !5, isLocal: false, isDefinition: true, scopeLine: 5, flags: DIFlagPrototyped, isOptimized: true, unit: !0, retainedNodes: !8)
     49 !5 = !DISubroutineType(types: !6)
     50 !6 = !{null, !7, !7}
     51 !7 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char)
     52 !8 = !{!9}
     53 !9 = !DILocalVariable(name: "entry", scope: !4, file: !1, line: 6, type: !7)
     54 !10 = !DILocalVariable(name: "ptr32", scope: !4, file: !1, line: 240, type: !11)
     55 !11 = !DICompositeType(tag: DW_TAG_array_type, baseType: !12, elements: !14)
     56 !12 = !DIDerivedType(tag: DW_TAG_typedef, name: "__uint32_t", file: !1, line: 41, baseType: !13)
     57 !13 = !DIBasicType(name: "unsigned int", size: 32, encoding: DW_ATE_unsigned)
     58 !14 = !{!15}
     59 !15 = !DISubrange(count: !16)
     60 !16 = !DILocalVariable(name: "__vla_expr", scope: !4, type: !17, flags: DIFlagArtificial)
     61 !17 = !DIBasicType(name: "long unsigned int", size: 64, encoding: DW_ATE_unsigned)
     62 !18 = !DILocation(line: 6, scope: !4)
     63