113 lines · plain
1; RUN: opt -passes=instcombine < %s -S | FileCheck %s2 3; This tests dbg.declare lowering for CallInst users of an alloca. The4; resulting dbg.value expressions should add a deref to the declare's expression.5 6; Hand-reduced from this example (-g -Og -mllvm -disable-llvm-optzns -gno-column-info):7 8; static volatile int sink;9; static void escape(int &c) { sink = c; }10; static bool empty ( int p1 ) { return p1 == 0; }11; int main() {12; int d1 = 42;13; while (!empty(d1))14; escape(d1);15; return 0;16; }17 18target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"19target triple = "x86_64-unknown-linux-gnu"20 21@_ZL4sink = internal global i32 0, align 4, !dbg !022 23; CHECK-LABEL: @main24define dso_local i32 @main() !dbg !12 {25entry:26 %retval = alloca i32, align 427 %d1 = alloca i32, align 428 store i32 0, ptr %retval, align 429 call void @llvm.lifetime.start.p0(ptr %d1) #4, !dbg !1730; CHECK: #dbg_value(i32 42, [[METADATA_IDX1:![0-9]+]], !DIExpression(),31; CHECK-NEXT: store32 call void @llvm.dbg.declare(metadata ptr %d1, metadata !16, metadata !DIExpression()), !dbg !1733 store i32 42, ptr %d1, align 4, !dbg !1734 br label %while.cond, !dbg !2235 36while.cond: ; preds = %while.body, %entry37; CHECK: #dbg_value(i32 %0, [[METADATA_IDX1]], !DIExpression(),38; CHECK-NEXT: call zeroext i1 @_ZL5emptyi39 %0 = load i32, ptr %d1, align 4, !dbg !2240 %call = call zeroext i1 @_ZL5emptyi(i32 %0), !dbg !2241 %lnot = xor i1 %call, true, !dbg !2242 br i1 %lnot, label %while.body, label %while.end, !dbg !2243 44while.body: ; preds = %while.cond45; CHECK: #dbg_value(ptr %d1, [[METADATA_IDX1]], !DIExpression(DW_OP_deref),46; CHECK-NEXT: call void @_ZL6escapeRi47 call void @_ZL6escapeRi(ptr dereferenceable(4) %d1), !dbg !2348 br label %while.cond, !dbg !22, !llvm.loop !2449 50while.end: ; preds = %while.cond51 call void @llvm.lifetime.end.p0(ptr %d1) #4, !dbg !2552 ret i32 0, !dbg !2653}54 55declare void @llvm.lifetime.start.p0(ptr nocapture)56 57declare void @llvm.dbg.declare(metadata, metadata, metadata)58 59define internal zeroext i1 @_ZL5emptyi(i32 %p1) !dbg !27 {60 ret i1 false61}62 63define internal void @_ZL6escapeRi(ptr dereferenceable(4) %c) #3 !dbg !34 {64 ret void65}66 67declare void @llvm.lifetime.end.p0(ptr nocapture) #168 69!llvm.dbg.cu = !{!2}70!llvm.module.flags = !{!8, !9, !10}71!llvm.ident = !{!11}72 73; CHECK: DIGlobalVariableExpression74; CHECK: [[METADATA_IDX1]] = !DILocalVariable(name: "d1"75 76!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())77!1 = distinct !DIGlobalVariable(name: "sink", linkageName: "_ZL4sink", scope: !2, file: !3, line: 2, type: !6, isLocal: true, isDefinition: true)78!2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "clang", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5, nameTableKind: None)79!3 = !DIFile(filename: "lower-dbg-declare.cpp", directory: "")80!4 = !{}81!5 = !{!0}82!6 = !DIDerivedType(tag: DW_TAG_volatile_type, baseType: !7)83!7 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)84!8 = !{i32 2, !"Dwarf Version", i32 4}85!9 = !{i32 2, !"Debug Info Version", i32 3}86!10 = !{i32 1, !"wchar_size", i32 4}87!11 = !{!"clang"}88!12 = distinct !DISubprogram(name: "main", scope: !3, file: !3, line: 5, type: !13, scopeLine: 5, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !15)89!13 = !DISubroutineType(types: !14)90!14 = !{!7}91!15 = !{!16}92!16 = !DILocalVariable(name: "d1", scope: !12, file: !3, line: 6, type: !7)93!17 = !DILocation(line: 6, scope: !12)94!22 = !DILocation(line: 7, scope: !12)95!23 = !DILocation(line: 8, scope: !12)96!24 = distinct !{!24, !22, !23}97!25 = !DILocation(line: 10, scope: !12)98!26 = !DILocation(line: 9, scope: !12)99!27 = distinct !DISubprogram(name: "empty", linkageName: "_ZL5emptyi", scope: !3, file: !3, line: 4, type: !28, scopeLine: 4, flags: DIFlagPrototyped, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !31)100!28 = !DISubroutineType(types: !29)101!29 = !{!30, !7}102!30 = !DIBasicType(name: "bool", size: 8, encoding: DW_ATE_boolean)103!31 = !{!32}104!32 = !DILocalVariable(name: "p1", arg: 1, scope: !27, file: !3, line: 4, type: !7)105!33 = !DILocation(line: 4, scope: !27)106!34 = distinct !DISubprogram(name: "escape", linkageName: "_ZL6escapeRi", scope: !3, file: !3, line: 3, type: !35, scopeLine: 3, flags: DIFlagPrototyped, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !38)107!35 = !DISubroutineType(types: !36)108!36 = !{null, !37}109!37 = !DIDerivedType(tag: DW_TAG_reference_type, baseType: !7, size: 64)110!38 = !{!39}111!39 = !DILocalVariable(name: "c", arg: 1, scope: !34, file: !3, line: 3, type: !37)112!42 = !DILocation(line: 3, scope: !34)113