Commit 454777f7 authored by Hans Wennborg's avatar Hans Wennborg
Browse files

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.
------------------------------------------------------------------------

llvm-svn: 277078
parent 6da6f088
Loading
Loading
Loading
Loading
+6 −7
Original line number Diff line number Diff line
@@ -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)
+1 −1
Original line number Diff line number Diff line
@@ -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
+44 −0
Original line number Diff line number Diff line
; 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: "<stdin>", 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)