Index: lib/CodeGen/CGDebugInfo.h =================================================================== --- lib/CodeGen/CGDebugInfo.h +++ lib/CodeGen/CGDebugInfo.h @@ -133,6 +133,7 @@ llvm::DenseMap DIFileCache; llvm::DenseMap SPCache; + llvm::DenseMap ParmCache; /// Cache declarations relevant to DW_TAG_imported_declarations (C++ /// using declarations) that aren't covered by other more specific caches. llvm::DenseMap DeclCache; Index: lib/CodeGen/CGDebugInfo.cpp =================================================================== --- lib/CodeGen/CGDebugInfo.cpp +++ lib/CodeGen/CGDebugInfo.cpp @@ -18,6 +18,7 @@ #include "CodeGenFunction.h" #include "CodeGenModule.h" #include "ConstantEmitter.h" +#include "clang/Analysis/Analyses/ExprMutationAnalyzer.h" #include "clang/AST/ASTContext.h" #include "clang/AST/DeclFriend.h" #include "clang/AST/DeclObjC.h" @@ -3880,6 +3881,11 @@ llvm::DebugLoc::get(Line, Column, Scope, CurInlinedAt), Builder.GetInsertBlock()); + if (ArgNo) { + auto *PD = dyn_cast(VD); + ParmCache[PD].reset(D); + } + return D; } @@ -4526,6 +4532,25 @@ if (auto MD = TypeCache[RT]) DBuilder.retainType(cast(MD)); + if (CGM.getCodeGenOpts().EnableDebugEntryValues && + CGM.getLangOpts().Optimize) { + for (auto &SP : DeclCache) { + auto *D = SP.first; + if (const auto *FD = dyn_cast_or_null(D)) { + const Stmt *FuncBody = (*FD).getBody(); + for (auto Parm : FD->parameters()) { + ExprMutationAnalyzer FuncAnalyzer(*FuncBody, CGM.getContext()); + if (!FuncAnalyzer.isMutated(Parm)) { + auto I = ParmCache.find(Parm); + if (I != ParmCache.end()) { + auto *DIParm = cast(I->second); + DIParm->setIsNotModified(); + } + } + } + } + } + } DBuilder.finalize(); }