Index: lib/CodeGen/AsmPrinter/DwarfDebug.cpp =================================================================== --- lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -669,6 +669,11 @@ NewCU.setSection(Asm->getObjFileLowering().getDwarfInfoSection()); } + // Create DIEs for function declaraions used for dbg call sites. + for (auto Scope : DIUnit->getRetainedTypes()) + if (auto *SP = dyn_cast_or_null(Scope)) + NewCU.getOrCreateSubprogramDIE(SP); + CUMap.insert({DIUnit, &NewCU}); CUDieMap.insert({&NewCU.getUnitDie(), &NewCU}); return NewCU; Index: lib/IR/Verifier.cpp =================================================================== --- lib/IR/Verifier.cpp +++ lib/IR/Verifier.cpp @@ -2223,8 +2223,9 @@ MDs.empty() ? nullptr : MDs.front().second); } else if (F.isDeclaration()) { for (const auto &I : MDs) { - AssertDI(I.first != LLVMContext::MD_dbg, - "function declaration may not have a !dbg attachment", &F); + AssertDI(I.first != LLVMContext::MD_dbg || + !cast(I.second)->isDistinct(), + "function declaration may only have a unique !dbg attachment", &F); Assert(I.first != LLVMContext::MD_prof, "function declaration may not have a !prof attachment", &F); Index: test/Verifier/metadata-function-dbg.ll =================================================================== --- test/Verifier/metadata-function-dbg.ll +++ test/Verifier/metadata-function-dbg.ll @@ -1,8 +1,11 @@ ; RUN: llvm-as %s -disable-output 2>&1 | FileCheck %s -; CHECK: function declaration may not have a !dbg attachment +; CHECK: function declaration may only have a unique !dbg attachment declare !dbg !4 void @f1() +; CHECK-NOT: function declaration may only have a unique !dbg attachment +declare !dbg !6 void @f5() + ; CHECK: function must have a single !dbg attachment define void @f2() !dbg !4 !dbg !4 { unreachable @@ -31,7 +34,9 @@ !0 = !{i32 2, !"Debug Info Version", i32 3} !llvm.dbg.cu = !{!1} -!1 = distinct !DICompileUnit(language: DW_LANG_C99, file: !2) +!1 = distinct !DICompileUnit(language: DW_LANG_C99, file: !2, retainedTypes: !5) !2 = !DIFile(filename: "t.c", directory: "/path/to/dir") !3 = !{} !4 = distinct !DISubprogram(name: "foo", scope: !1, file: !2, unit: !1) +!5 = !{!6} +!6 = !DISubprogram(name: "f5", scope: !1, file: !2, unit: !1, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized)