[llvm] DiagnosticInfo: Fix stack-use-after-scope in DiagnosticInfoStackSize (PR #190442)

via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 3 20:44:51 PDT 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-ir

Author: Jinsong Ji (jsji)

<details>
<summary>Changes</summary>

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


---
Full diff: https://github.com/llvm/llvm-project/pull/190442.diff


1 Files Affected:

- (modified) llvm/include/llvm/IR/DiagnosticInfo.h (+2-1) 


``````````diff
diff --git a/llvm/include/llvm/IR/DiagnosticInfo.h b/llvm/include/llvm/IR/DiagnosticInfo.h
index d72b1f42d84cf..189a8775a0468 100644
--- a/llvm/include/llvm/IR/DiagnosticInfo.h
+++ b/llvm/include/llvm/IR/DiagnosticInfo.h
@@ -501,12 +501,13 @@ class LLVM_ABI DiagnosticInfoResourceLimit
 
 class LLVM_ABI DiagnosticInfoStackSize : public DiagnosticInfoResourceLimit {
   void anchor() override;
+  const Twine ResourceName{"stack frame size"};
 
 public:
   DiagnosticInfoStackSize(const Function &Fn, uint64_t StackSize,
                           uint64_t StackLimit,
                           DiagnosticSeverity Severity = DS_Warning)
-      : DiagnosticInfoResourceLimit(Fn, "stack frame size", StackSize,
+      : DiagnosticInfoResourceLimit(Fn, ResourceName, StackSize,
                                     StackLimit, Severity, DK_StackSize) {}
 
   uint64_t getStackSize() const { return getResourceSize(); }

``````````

</details>


https://github.com/llvm/llvm-project/pull/190442


More information about the llvm-commits mailing list