Index: lib/CodeGen/CGDebugInfo.h =================================================================== --- lib/CodeGen/CGDebugInfo.h +++ lib/CodeGen/CGDebugInfo.h @@ -308,6 +308,7 @@ ~CGDebugInfo(); void finalize(); + void finalizeSP(llvm::DISubprogram *SP) { DBuilder.finalizeSP(SP); } /// Module debugging: Support for building PCMs. /// @{ Index: lib/CodeGen/CGVTables.cpp =================================================================== --- lib/CodeGen/CGVTables.cpp +++ lib/CodeGen/CGVTables.cpp @@ -152,6 +152,12 @@ llvm::Value *Callee = CGM.GetAddrOfFunction(GD, Ty, /*ForVTable=*/true); llvm::Function *BaseFn = cast(Callee); + // We may not clone a subprogram that contains temporary metadata, so finalize + // it now - we will not be modifying it. + if (CGDebugInfo *DI = CGM.getModuleDebugInfo()) + if (llvm::DISubprogram *SP = BaseFn->getSubprogram()) + DI->finalizeSP(SP); + // Clone to thunk. llvm::ValueToValueMapTy VMap; llvm::Function *NewFn = llvm::CloneFunction(BaseFn, VMap);