diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp --- a/clang/lib/CodeGen/CGDebugInfo.cpp +++ b/clang/lib/CodeGen/CGDebugInfo.cpp @@ -2149,6 +2149,9 @@ void CGDebugInfo::addHeapAllocSiteMetadata(llvm::CallBase *CI, QualType AllocatedTy, SourceLocation Loc) { + if (CGM.getCodeGenOpts().getDebugInfo() <= + codegenoptions::DebugLineTablesOnly) + return; llvm::MDNode *node; if (AllocatedTy->isVoidType()) node = llvm::MDNode::get(CGM.getLLVMContext(), None); diff --git a/clang/lib/CodeGen/CGExprCXX.cpp b/clang/lib/CodeGen/CGExprCXX.cpp --- a/clang/lib/CodeGen/CGExprCXX.cpp +++ b/clang/lib/CodeGen/CGExprCXX.cpp @@ -1639,8 +1639,7 @@ EmitNewDeleteCall(*this, allocator, allocatorType, allocatorArgs); // Set !heapallocsite metadata on the call to operator new. - if (CGM.getCodeGenOpts().getDebugInfo() != codegenoptions::NoDebugInfo && - getDebugInfo()) + if (getDebugInfo()) if (auto *newCall = dyn_cast(RV.getScalarVal())) getDebugInfo()->addHeapAllocSiteMetadata(newCall, allocType, E->getExprLoc());