1; RUN: opt -instcombine < %s -S | FileCheck %s 2 3; This tests dbg.declare lowering for CallInst users of an alloca. The 4; resulting dbg.value expressions should add a deref to the declare's expression. 5 6; Hand-reduced from this example (-g -Og -fsanitize=address): 7 8; static volatile int sink; 9; struct OneElementVector { 10; int Element; 11; OneElementVector(int Element) : Element(Element) { sink = Element; } 12; bool empty() const { return false; } 13; }; 14; using container = OneElementVector; 15; static void escape(container &c) { sink = c.Element; } 16; int main() { 17; container d1 = {42}; 18; while (!d1.empty()) 19; escape(d1); 20; return 0; 21; } 22 23target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128" 24target triple = "x86_64-apple-macosx10.13.0" 25 26%struct.OneElementVector = type { i32 } 27 28define i1 @escape(%struct.OneElementVector* %d1) { 29 ret i1 false 30} 31 32; CHECK-LABEL: @main 33define i32 @main() !dbg !15 { 34entry: 35 %d1 = alloca %struct.OneElementVector, align 4 36 %0 = bitcast %struct.OneElementVector* %d1 to i8*, !dbg !34 37 38; CHECK: dbg.value(metadata %struct.OneElementVector* [[var:%.*]], metadata !DIExpression(DW_OP_deref)) 39; CHECK-NEXT: call i1 @escape 40 call void @llvm.dbg.declare(metadata %struct.OneElementVector* %d1, metadata !19, metadata !DIExpression()), !dbg !35 41 call i1 @escape(%struct.OneElementVector* %d1) 42 br label %while.cond, !dbg !37 43 44while.cond: ; preds = %while.body, %entry 45; CHECK: dbg.value(metadata %struct.OneElementVector* [[var]], metadata !DIExpression(DW_OP_deref)) 46; CHECK-NEXT: call i1 @escape 47 %call = call i1 @escape(%struct.OneElementVector* %d1), !dbg !38 48 %lnot = xor i1 %call, true, !dbg !39 49 br i1 %lnot, label %while.body, label %while.end, !dbg !37 50 51while.body: ; preds = %while.cond 52; CHECK: dbg.value(metadata %struct.OneElementVector* [[var]], metadata !DIExpression(DW_OP_deref)) 53; CHECK-NEXT: call i1 @escape 54 call i1 @escape(%struct.OneElementVector* %d1) 55 br label %while.cond, !dbg !37, !llvm.loop !42 56 57while.end: ; preds = %while.cond 58 ret i32 0, !dbg !45 59} 60 61; CHECK-LABEL: @main2 62define i32 @main2() { 63entry: 64 %d1 = alloca %struct.OneElementVector, align 4 65 %0 = bitcast %struct.OneElementVector* %d1 to i8*, !dbg !34 66 67; CHECK: dbg.value(metadata %struct.OneElementVector* [[var:%.*]], metadata !DIExpression(DW_OP_lit0, DW_OP_mul, DW_OP_deref)) 68; CHECK-NEXT: call i1 @escape 69 call void @llvm.dbg.declare(metadata %struct.OneElementVector* %d1, metadata !19, metadata !DIExpression(DW_OP_lit0, DW_OP_mul)), !dbg !35 70 call i1 @escape(%struct.OneElementVector* %d1) 71 br label %while.cond, !dbg !37 72 73while.cond: ; preds = %while.body, %entry 74; CHECK: dbg.value(metadata %struct.OneElementVector* [[var]], metadata !DIExpression(DW_OP_lit0, DW_OP_mul, DW_OP_deref)) 75; CHECK-NEXT: call i1 @escape 76 %call = call i1 @escape(%struct.OneElementVector* %d1), !dbg !38 77 %lnot = xor i1 %call, true, !dbg !39 78 br i1 %lnot, label %while.body, label %while.end, !dbg !37 79 80while.body: ; preds = %while.cond 81; CHECK: dbg.value(metadata %struct.OneElementVector* [[var]], metadata !DIExpression(DW_OP_lit0, DW_OP_mul, DW_OP_deref)) 82; CHECK-NEXT: call i1 @escape 83 call i1 @escape(%struct.OneElementVector* %d1) 84 br label %while.cond, !dbg !37, !llvm.loop !42 85 86while.end: ; preds = %while.cond 87 ret i32 0, !dbg !45 88} 89 90declare void @llvm.dbg.declare(metadata, metadata, metadata) 91 92!llvm.dbg.cu = !{!2} 93!llvm.asan.globals = !{!8} 94!llvm.module.flags = !{!10, !11, !12, !13} 95!llvm.ident = !{!14} 96 97!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression()) 98!1 = distinct !DIGlobalVariable(name: "sink", linkageName: "_ZL4sink", scope: !2, file: !3, line: 1, type: !6, isLocal: true, isDefinition: true) 99!2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "clang version 7.0.0 (trunk 337207) (llvm/trunk 337204)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5) 100!3 = !DIFile(filename: "test.cc", directory: "/Users/vsk/src/builds/llvm.org-master-RA") 101!4 = !{} 102!5 = !{!0} 103!6 = !DIDerivedType(tag: DW_TAG_volatile_type, baseType: !7) 104!7 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) 105!8 = !{} 106!9 = !{!"test.cc", i32 1, i32 21} 107!10 = !{i32 2, !"Dwarf Version", i32 4} 108!11 = !{i32 2, !"Debug Info Version", i32 3} 109!12 = !{i32 1, !"wchar_size", i32 4} 110!13 = !{i32 7, !"PIC Level", i32 2} 111!14 = !{!"clang version 7.0.0 (trunk 337207) (llvm/trunk 337204)"} 112!15 = distinct !DISubprogram(name: "main", scope: !3, file: !3, line: 18, type: !16, isLocal: false, isDefinition: true, scopeLine: 18, flags: DIFlagPrototyped, isOptimized: true, unit: !2, retainedNodes: !18) 113!16 = !DISubroutineType(types: !17) 114!17 = !{!7} 115!18 = !{!19} 116!19 = !DILocalVariable(name: "d1", scope: !15, file: !3, line: 21, type: !20) 117!20 = !DIDerivedType(tag: DW_TAG_typedef, name: "container", file: !3, line: 12, baseType: !21) 118!21 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "OneElementVector", file: !3, line: 3, size: 32, flags: DIFlagTypePassByValue, elements: !22, identifier: "_ZTS16OneElementVector") 119!22 = !{!23, !24, !28} 120!23 = !DIDerivedType(tag: DW_TAG_member, name: "Element", scope: !21, file: !3, line: 4, baseType: !7, size: 32) 121!24 = !DISubprogram(name: "OneElementVector", scope: !21, file: !3, line: 6, type: !25, isLocal: false, isDefinition: false, scopeLine: 6, flags: DIFlagPrototyped, isOptimized: true) 122!25 = !DISubroutineType(types: !26) 123!26 = !{null, !27, !7} 124!27 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !21, size: 64, flags: DIFlagArtificial | DIFlagObjectPointer) 125!28 = !DISubprogram(name: "empty", linkageName: "_ZNK16OneElementVector5emptyEv", scope: !21, file: !3, line: 8, type: !29, isLocal: false, isDefinition: false, scopeLine: 8, flags: DIFlagPrototyped, isOptimized: true) 126!29 = !DISubroutineType(types: !30) 127!30 = !{!31, !32} 128!31 = !DIBasicType(name: "bool", size: 8, encoding: DW_ATE_boolean) 129!32 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !33, size: 64, flags: DIFlagArtificial | DIFlagObjectPointer) 130!33 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !21) 131!34 = !DILocation(line: 21, column: 3, scope: !15) 132!35 = !DILocation(line: 21, column: 13, scope: !15) 133!36 = !DILocation(line: 21, column: 18, scope: !15) 134!37 = !DILocation(line: 22, column: 3, scope: !15) 135!38 = !DILocation(line: 22, column: 14, scope: !15) 136!39 = !DILocation(line: 22, column: 10, scope: !15) 137!40 = !DILocation(line: 23, column: 5, scope: !41) 138!41 = distinct !DILexicalBlock(scope: !15, file: !3, line: 22, column: 23) 139!42 = distinct !{!42, !37, !43} 140!43 = !DILocation(line: 24, column: 3, scope: !15) 141!44 = !DILocation(line: 26, column: 1, scope: !15) 142!45 = !DILocation(line: 25, column: 3, scope: !15) 143!46 = distinct !DISubprogram(name: "OneElementVector", linkageName: "_ZN16OneElementVectorC1Ei", scope: !21, file: !3, line: 6, type: !25, isLocal: false, isDefinition: true, scopeLine: 6, flags: DIFlagPrototyped, isOptimized: true, unit: !2, declaration: !24, retainedNodes: !47) 144!47 = !{!48, !50} 145!48 = !DILocalVariable(name: "this", arg: 1, scope: !46, type: !49, flags: DIFlagArtificial | DIFlagObjectPointer) 146!49 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !21, size: 64) 147!50 = !DILocalVariable(name: "Element", arg: 2, scope: !46, file: !3, line: 6, type: !7) 148!51 = !DILocation(line: 0, scope: !46) 149!52 = !DILocation(line: 6, column: 24, scope: !46) 150!53 = !DILocation(line: 6, column: 52, scope: !46) 151!54 = !DILocation(line: 6, column: 70, scope: !46) 152!55 = distinct !DISubprogram(name: "empty", linkageName: "_ZNK16OneElementVector5emptyEv", scope: !21, file: !3, line: 8, type: !29, isLocal: false, isDefinition: true, scopeLine: 8, flags: DIFlagPrototyped, isOptimized: true, unit: !2, declaration: !28, retainedNodes: !56) 153!56 = !{!57} 154!57 = !DILocalVariable(name: "this", arg: 1, scope: !55, type: !58, flags: DIFlagArtificial | DIFlagObjectPointer) 155!58 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !33, size: 64) 156!59 = !DILocation(line: 0, scope: !55) 157!60 = !DILocation(line: 8, column: 24, scope: !55) 158!61 = distinct !DISubprogram(name: "escape", linkageName: "_ZL6escapeR16OneElementVector", scope: !3, file: !3, line: 14, type: !62, isLocal: true, isDefinition: true, scopeLine: 14, flags: DIFlagPrototyped, isOptimized: true, unit: !2, retainedNodes: !65) 159!62 = !DISubroutineType(types: !63) 160!63 = !{null, !64} 161!64 = !DIDerivedType(tag: DW_TAG_reference_type, baseType: !20, size: 64) 162!65 = !{!66} 163!66 = !DILocalVariable(name: "c", arg: 1, scope: !61, file: !3, line: 14, type: !64) 164!67 = !DILocation(line: 14, column: 31, scope: !61) 165!68 = !DILocation(line: 15, column: 12, scope: !61) 166!69 = !{!70, !71, i64 0} 167!70 = !{!"_ZTS16OneElementVector", !71, i64 0} 168!71 = !{!"int", !72, i64 0} 169!72 = !{!"omnipotent char", !73, i64 0} 170!73 = !{!"Simple C++ TBAA"} 171!74 = !DILocation(line: 15, column: 8, scope: !61) 172!75 = !{!71, !71, i64 0} 173!76 = !DILocation(line: 16, column: 1, scope: !61) 174!77 = distinct !DISubprogram(name: "OneElementVector", linkageName: "_ZN16OneElementVectorC2Ei", scope: !21, file: !3, line: 6, type: !25, isLocal: false, isDefinition: true, scopeLine: 6, flags: DIFlagPrototyped, isOptimized: true, unit: !2, declaration: !24, retainedNodes: !78) 175!78 = !{!79, !80} 176!79 = !DILocalVariable(name: "this", arg: 1, scope: !77, type: !49, flags: DIFlagArtificial | DIFlagObjectPointer) 177!80 = !DILocalVariable(name: "Element", arg: 2, scope: !77, file: !3, line: 6, type: !7) 178!81 = !DILocation(line: 0, scope: !77) 179!82 = !DILocation(line: 6, column: 24, scope: !77) 180!83 = !DILocation(line: 6, column: 35, scope: !77) 181!84 = !DILocation(line: 6, column: 59, scope: !85) 182!85 = distinct !DILexicalBlock(scope: !77, file: !3, line: 6, column: 52) 183!86 = !DILocation(line: 6, column: 70, scope: !77) 184