DiagnosticInfo: Fix stack-use-after-scope in DiagnosticInfoStackSize (#190442)

The string literal "stack frame size" passed to the base class
constructor created a temporary Twine that was destroyed after
the base constructor completed, leaving a dangling reference.

Fix by storing the Twine as a member variable in the derived class,
ensuring it lives as long as the diagnostic object itself.

Fixes ASAN stack-use-after-scope error in
  Clang :: Misc/backend-stack-frame-diagnostics-fallback.cpp
  LLVM :: CodeGen/X86/2007-04-24-Huge-Stack.ll
  LLVM :: CodeGen/X86/huge-stack-offset.ll
  LLVM :: CodeGen/X86/huge-stack-offset2.ll
  LLVM :: CodeGen/X86/huge-stack.ll
  LLVM :: CodeGen/X86/large-displacements.ll
  LLVM :: CodeGen/X86/stack-clash-extra-huge.ll
  LLVM :: CodeGen/X86/warn-stack.ll
  LLVM :: CodeGen/X86/win64-stackprobe-overflow.ll
This commit is contained in:
Jinsong Ji 2026-04-04 10:52:54 -04:00 committed by GitHub
parent a8ad2a7d73
commit ee405335f0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -501,13 +501,14 @@ public:
class LLVM_ABI DiagnosticInfoStackSize : public DiagnosticInfoResourceLimit {
void anchor() override;
const Twine ResourceNameStr{"stack frame size"};
public:
DiagnosticInfoStackSize(const Function &Fn, uint64_t StackSize,
uint64_t StackLimit,
DiagnosticSeverity Severity = DS_Warning)
: DiagnosticInfoResourceLimit(Fn, "stack frame size", StackSize,
StackLimit, Severity, DK_StackSize) {}
: DiagnosticInfoResourceLimit(Fn, ResourceNameStr, StackSize, StackLimit,
Severity, DK_StackSize) {}
uint64_t getStackSize() const { return getResourceSize(); }
uint64_t getStackLimit() const { return getResourceLimit(); }