Index: lib/CodeGen/AsmPrinter/CodeViewDebug.cpp =================================================================== --- lib/CodeGen/AsmPrinter/CodeViewDebug.cpp +++ lib/CodeGen/AsmPrinter/CodeViewDebug.cpp @@ -117,6 +117,7 @@ if (!MMI->getModule()->getNamedMetadata("llvm.dbg.cu") || !AP->getObjFileLowering().getCOFFDebugSymbolsSection()) { Asm = nullptr; + MMI->setDebugInfoAvailability(false); return; } // Tell MMI that we have debug info. Index: lib/CodeGen/AsmPrinter/DwarfDebug.cpp =================================================================== --- lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -701,15 +701,18 @@ void DwarfDebug::beginModule() { NamedRegionTimer T(DbgTimerName, DbgTimerDescription, DWARFGroupName, DWARFGroupDescription, TimePassesIsEnabled); - if (DisableDebugInfoPrinting) + if (DisableDebugInfoPrinting) { + MMI->setDebugInfoAvailability(false); return; + } const Module *M = MMI->getModule(); unsigned NumDebugCUs = std::distance(M->debug_compile_units_begin(), M->debug_compile_units_end()); // Tell MMI whether we have debug info. - MMI->setDebugInfoAvailability(NumDebugCUs > 0); + assert(MMI->hasDebugInfo() == (NumDebugCUs > 0) && + "DebugInfoAvailabilty initialized unexpectedly"); SingleCU = NumDebugCUs == 1; DenseMap> GVMap; Index: lib/CodeGen/MachineModuleInfo.cpp =================================================================== --- lib/CodeGen/MachineModuleInfo.cpp +++ lib/CodeGen/MachineModuleInfo.cpp @@ -206,10 +206,11 @@ bool MachineModuleInfo::doInitialization(Module &M) { ObjFileMMI = nullptr; CurCallSite = 0; - DbgInfoAvailable = UsesVAFloatArgument = UsesMorestackAddr = false; + UsesVAFloatArgument = UsesMorestackAddr = false; HasSplitStack = HasNosplitStack = false; AddrLabelSymbols = nullptr; TheModule = &M; + DbgInfoAvailable = !empty(M.debug_compile_units()); return false; } Index: test/CodeGen/AArch64/fast-isel-dbg.ll =================================================================== --- /dev/null +++ test/CodeGen/AArch64/fast-isel-dbg.ll @@ -0,0 +1,27 @@ +; RUN: llc -o - %s -fast-isel -stop-before=expand-isel-pseudos | FileCheck %s +; Make sure fast-isel produces DBG_VALUE instructions even if no debug printer +; is scheduled because of -stop-before. +target triple="aarch64--" + +!0 = !DIFile(filename: "fast-isel-dbg.ll", directory: "/") +!1 = distinct !DICompileUnit(file: !0, language: DW_LANG_C, emissionKind: LineTablesOnly) +!2 = distinct !DISubprogram(name: "func", unit: !1) +!3 = !DILocation(line: 17, scope: !2) +!4 = !DILocation(line: 42, scope: !2) +!5 = !DILocalVariable(name: "a", arg: 1, scope: !2, file: !0, line: 17, type: !6) +!6 = !DIBasicType(name: "unsigned int", size: 32, encoding: DW_ATE_unsigned) + +!llvm.dbg.cu = !{!1} +!llvm.module.flags = !{!10, !11} +!10 = !{i32 2, !"Dwarf Version", i32 4} +!11 = !{i32 2, !"Debug Info Version", i32 3} + +; CHECK-LABEL: name: func +; CHECK: DBG_VALUE +define void @func(i32 %a) !dbg !2 { + call void @llvm.dbg.declare(metadata i32 %a, metadata !5, metadata !DIExpression()), !dbg !3 + ret void +} + +declare void @llvm.dbg.declare(metadata, metadata, metadata) #1 +attributes #1 = { nounwind readnone speculatable }