From 83c76e2427a852334afd0e9f709c4a5a4f6db01b Mon Sep 17 00:00:00 2001 From: Hans Wennborg Date: Thu, 28 Jul 2016 23:15:39 +0000 Subject: [PATCH] Merging r276956: ------------------------------------------------------------------------ r276956 | majnemer | 2016-07-27 22:03:22 -0700 (Wed, 27 Jul 2016) | 6 lines [CodeView] Don't crash on functions without subprograms A function may have instructions annotated with debug info without having a subprogram. This fixes PR28747. ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_39@277078 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/AsmPrinter/CodeViewDebug.cpp | 13 ++++--- test/DebugInfo/COFF/inlining-same-name.ll | 2 +- test/DebugInfo/COFF/pr28747.ll | 44 +++++++++++++++++++++++ 3 files changed, 51 insertions(+), 8 deletions(-) create mode 100644 test/DebugInfo/COFF/pr28747.ll diff --git a/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp b/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp index b0ba5712220..ebf80dea2c4 100644 --- a/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp +++ b/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp @@ -214,10 +214,7 @@ TypeIndex CodeViewDebug::getScopeIndex(const DIScope *Scope) { } TypeIndex CodeViewDebug::getFuncIdForSubprogram(const DISubprogram *SP) { - // It's possible to ask for the FuncId of a function which doesn't have a - // subprogram: inlining a function with debug info into a function with none. - if (!SP) - return TypeIndex::None(); + assert(SP); // Check if we've already translated this subprogram. auto I = TypeIndices.find({SP, nullptr}); @@ -621,11 +618,12 @@ void CodeViewDebug::emitDebugInfoForFunction(const Function *GV, std::string FuncName; auto *SP = GV->getSubprogram(); + assert(SP); setCurrentSubprogram(SP); // If we have a display name, build the fully qualified name by walking the // chain of scopes. - if (SP != nullptr && !SP->getDisplayName().empty()) + if (!SP->getDisplayName().empty()) FuncName = getFullyQualifiedName(SP->getScope().resolve(), SP->getDisplayName()); @@ -864,7 +862,7 @@ void CodeViewDebug::collectVariableInfo(const DISubprogram *SP) { void CodeViewDebug::beginFunction(const MachineFunction *MF) { assert(!CurFn && "Can't process two functions at once!"); - if (!Asm || !MMI->hasDebugInfo()) + if (!Asm || !MMI->hasDebugInfo() || !MF->getFunction()->getSubprogram()) return; DebugHandlerBase::beginFunction(MF); @@ -1939,7 +1937,8 @@ void CodeViewDebug::beginInstruction(const MachineInstr *MI) { DebugHandlerBase::beginInstruction(MI); // Ignore DBG_VALUE locations and function prologue. - if (!Asm || MI->isDebugValue() || MI->getFlag(MachineInstr::FrameSetup)) + if (!Asm || !CurFn || MI->isDebugValue() || + MI->getFlag(MachineInstr::FrameSetup)) return; DebugLoc DL = MI->getDebugLoc(); if (DL == PrevInstLoc || !DL) diff --git a/test/DebugInfo/COFF/inlining-same-name.ll b/test/DebugInfo/COFF/inlining-same-name.ll index 44b87912f80..fda5a6dc6ff 100644 --- a/test/DebugInfo/COFF/inlining-same-name.ll +++ b/test/DebugInfo/COFF/inlining-same-name.ll @@ -33,7 +33,7 @@ target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128" target triple = "x86_64-pc-windows-msvc" -define void @main(i32* %i.i) { +define void @main(i32* %i.i) !dbg !16 { store volatile i32 3, i32* %i.i, !dbg !6 store volatile i32 3, i32* %i.i, !dbg !19 ret void diff --git a/test/DebugInfo/COFF/pr28747.ll b/test/DebugInfo/COFF/pr28747.ll new file mode 100644 index 00000000000..d19a2fae682 --- /dev/null +++ b/test/DebugInfo/COFF/pr28747.ll @@ -0,0 +1,44 @@ +; RUN: llc < %s | FileCheck %s + +; CHECK: .section .debug$S,"dr"{{$}} +; CHECK-NEXT: .p2align 2 +; CHECK-NEXT: .long 4 +; CHECK-NEXT: .cv_filechecksums +; CHECK-NEXT: .cv_stringtable + +target datalayout = "e-m:x-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32" +target triple = "i686-pc-windows-msvc18.0.0" + +define void @baz() { +entry: + %x.i.i = alloca i32, align 4 + call void @llvm.dbg.declare(metadata i32* %x.i.i, metadata !6, metadata !12), !dbg !13 + store i32 5, i32* %x.i.i, align 4, !dbg !13 + ret void +} + +; Function Attrs: nounwind readnone +declare void @llvm.dbg.declare(metadata, metadata, metadata) #0 + +attributes #0 = { nounwind readnone } + +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!3, !4} +!llvm.ident = !{!5} + +!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 4.0.0 (trunk 276756) (llvm/trunk 276952)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2) +!1 = !DIFile(filename: "-", directory: "/") +!2 = !{} +!3 = !{i32 2, !"CodeView", i32 1} +!4 = !{i32 2, !"Debug Info Version", i32 3} +!5 = !{!"clang version 4.0.0 (trunk 276756) (llvm/trunk 276952)"} +!6 = !DILocalVariable(name: "x", scope: !7, file: !8, line: 1, type: !11) +!7 = distinct !DISubprogram(name: "foo", scope: !8, file: !8, line: 1, type: !9, isLocal: true, isDefinition: true, scopeLine: 1, isOptimized: false, unit: !0, variables: !2) +!8 = !DIFile(filename: "", directory: "/") +!9 = !DISubroutineType(types: !10) +!10 = !{null} +!11 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed) +!12 = !DIExpression() +!13 = !DILocation(line: 1, column: 56, scope: !7, inlinedAt: !14) +!14 = distinct !DILocation(line: 2, column: 52, scope: !15) +!15 = distinct !DISubprogram(name: "bar", scope: !8, file: !8, line: 2, type: !9, isLocal: true, isDefinition: true, scopeLine: 2, isOptimized: false, unit: !0, variables: !2) -- 2.49.0