Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit 83c76e2

Browse files
committed
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
1 parent 7653e62 commit 83c76e2

File tree

3 files changed

+51
-8
lines changed

3 files changed

+51
-8
lines changed

lib/CodeGen/AsmPrinter/CodeViewDebug.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -214,10 +214,7 @@ TypeIndex CodeViewDebug::getScopeIndex(const DIScope *Scope) {
214214
}
215215

216216
TypeIndex CodeViewDebug::getFuncIdForSubprogram(const DISubprogram *SP) {
217-
// It's possible to ask for the FuncId of a function which doesn't have a
218-
// subprogram: inlining a function with debug info into a function with none.
219-
if (!SP)
220-
return TypeIndex::None();
217+
assert(SP);
221218

222219
// Check if we've already translated this subprogram.
223220
auto I = TypeIndices.find({SP, nullptr});
@@ -621,11 +618,12 @@ void CodeViewDebug::emitDebugInfoForFunction(const Function *GV,
621618

622619
std::string FuncName;
623620
auto *SP = GV->getSubprogram();
621+
assert(SP);
624622
setCurrentSubprogram(SP);
625623

626624
// If we have a display name, build the fully qualified name by walking the
627625
// chain of scopes.
628-
if (SP != nullptr && !SP->getDisplayName().empty())
626+
if (!SP->getDisplayName().empty())
629627
FuncName =
630628
getFullyQualifiedName(SP->getScope().resolve(), SP->getDisplayName());
631629

@@ -864,7 +862,7 @@ void CodeViewDebug::collectVariableInfo(const DISubprogram *SP) {
864862
void CodeViewDebug::beginFunction(const MachineFunction *MF) {
865863
assert(!CurFn && "Can't process two functions at once!");
866864

867-
if (!Asm || !MMI->hasDebugInfo())
865+
if (!Asm || !MMI->hasDebugInfo() || !MF->getFunction()->getSubprogram())
868866
return;
869867

870868
DebugHandlerBase::beginFunction(MF);
@@ -1939,7 +1937,8 @@ void CodeViewDebug::beginInstruction(const MachineInstr *MI) {
19391937
DebugHandlerBase::beginInstruction(MI);
19401938

19411939
// Ignore DBG_VALUE locations and function prologue.
1942-
if (!Asm || MI->isDebugValue() || MI->getFlag(MachineInstr::FrameSetup))
1940+
if (!Asm || !CurFn || MI->isDebugValue() ||
1941+
MI->getFlag(MachineInstr::FrameSetup))
19431942
return;
19441943
DebugLoc DL = MI->getDebugLoc();
19451944
if (DL == PrevInstLoc || !DL)

test/DebugInfo/COFF/inlining-same-name.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
3434
target triple = "x86_64-pc-windows-msvc"
3535

36-
define void @main(i32* %i.i) {
36+
define void @main(i32* %i.i) !dbg !16 {
3737
store volatile i32 3, i32* %i.i, !dbg !6
3838
store volatile i32 3, i32* %i.i, !dbg !19
3939
ret void

test/DebugInfo/COFF/pr28747.ll

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
; RUN: llc < %s | FileCheck %s
2+
3+
; CHECK: .section .debug$S,"dr"{{$}}
4+
; CHECK-NEXT: .p2align 2
5+
; CHECK-NEXT: .long 4
6+
; CHECK-NEXT: .cv_filechecksums
7+
; CHECK-NEXT: .cv_stringtable
8+
9+
target datalayout = "e-m:x-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32"
10+
target triple = "i686-pc-windows-msvc18.0.0"
11+
12+
define void @baz() {
13+
entry:
14+
%x.i.i = alloca i32, align 4
15+
call void @llvm.dbg.declare(metadata i32* %x.i.i, metadata !6, metadata !12), !dbg !13
16+
store i32 5, i32* %x.i.i, align 4, !dbg !13
17+
ret void
18+
}
19+
20+
; Function Attrs: nounwind readnone
21+
declare void @llvm.dbg.declare(metadata, metadata, metadata) #0
22+
23+
attributes #0 = { nounwind readnone }
24+
25+
!llvm.dbg.cu = !{!0}
26+
!llvm.module.flags = !{!3, !4}
27+
!llvm.ident = !{!5}
28+
29+
!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)
30+
!1 = !DIFile(filename: "-", directory: "/")
31+
!2 = !{}
32+
!3 = !{i32 2, !"CodeView", i32 1}
33+
!4 = !{i32 2, !"Debug Info Version", i32 3}
34+
!5 = !{!"clang version 4.0.0 (trunk 276756) (llvm/trunk 276952)"}
35+
!6 = !DILocalVariable(name: "x", scope: !7, file: !8, line: 1, type: !11)
36+
!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)
37+
!8 = !DIFile(filename: "<stdin>", directory: "/")
38+
!9 = !DISubroutineType(types: !10)
39+
!10 = !{null}
40+
!11 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
41+
!12 = !DIExpression()
42+
!13 = !DILocation(line: 1, column: 56, scope: !7, inlinedAt: !14)
43+
!14 = distinct !DILocation(line: 2, column: 52, scope: !15)
44+
!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)

0 commit comments

Comments
 (0)