[llvm] DiagnosticInfo: Fix stack-use-after-scope in DiagnosticInfoStackSize (PR #190442)
Jinsong Ji via llvm-commits
llvm-commits at lists.llvm.org
Sat Apr 4 07:15:04 PDT 2026
https://github.com/jsji updated https://github.com/llvm/llvm-project/pull/190442
>From b0b1627300a9c194be8fa29d13db3aacc1091a3c Mon Sep 17 00:00:00 2001
From: Jinsong Ji <jinsong.ji at intel.com>
Date: Sat, 4 Apr 2026 04:59:12 +0200
Subject: [PATCH 1/2] DiagnosticInfo: Fix stack-use-after-scope in
DiagnosticInfoStackSize
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
---
llvm/include/llvm/IR/DiagnosticInfo.h | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
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(); }
>From c34e370526a9d359dfabefb753f6b2e79f1ee8a6 Mon Sep 17 00:00:00 2001
From: Jinsong Ji <jinsong.ji at intel.com>
Date: Sat, 4 Apr 2026 16:14:16 +0200
Subject: [PATCH 2/2] fix shadowing
---
llvm/include/llvm/IR/DiagnosticInfo.h | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/llvm/include/llvm/IR/DiagnosticInfo.h b/llvm/include/llvm/IR/DiagnosticInfo.h
index 189a8775a0468..28fbfa757b1cc 100644
--- a/llvm/include/llvm/IR/DiagnosticInfo.h
+++ b/llvm/include/llvm/IR/DiagnosticInfo.h
@@ -501,14 +501,14 @@ class LLVM_ABI DiagnosticInfoResourceLimit
class LLVM_ABI DiagnosticInfoStackSize : public DiagnosticInfoResourceLimit {
void anchor() override;
- const Twine ResourceName{"stack frame size"};
+ const Twine ResourceNameStr{"stack frame size"};
public:
DiagnosticInfoStackSize(const Function &Fn, uint64_t StackSize,
uint64_t StackLimit,
DiagnosticSeverity Severity = DS_Warning)
- : DiagnosticInfoResourceLimit(Fn, ResourceName, 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(); }
More information about the llvm-commits
mailing list