diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp --- a/llvm/lib/Transforms/Utils/Local.cpp +++ b/llvm/lib/Transforms/Utils/Local.cpp @@ -1733,9 +1733,11 @@ void llvm::salvageDebugInfoForDbgValues( Instruction &I, ArrayRef DbgUsers) { - // This is an arbitrary chosen limit on the maximum number of values we can - // salvage up to in a DIArgList, used for performance reasons. + // These are arbitrary chosen limits on the maximum number of values and the + // maximum size of a debug expression we can salvage up to, used for + // performance reasons. const unsigned MaxDebugArgs = 16; + const unsigned MaxExpressionSize = 128; bool Salvaged = false; for (auto *DII : DbgUsers) { @@ -1772,9 +1774,10 @@ break; DII->replaceVariableLocationOp(&I, Op0); - if (AdditionalValues.empty()) { + bool IsValidSalvageExpr = SalvagedExpr->getNumElements() <= MaxExpressionSize; + if (AdditionalValues.empty() && IsValidSalvageExpr) { DII->setExpression(SalvagedExpr); - } else if (isa(DII) && + } else if (isa(DII) && IsValidSalvageExpr && DII->getNumVariableLocationOps() + AdditionalValues.size() <= MaxDebugArgs) { DII->addVariableLocationOps(AdditionalValues, SalvagedExpr);