aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CodeGenModule.h
diff options
context:
space:
mode:
authorBoaz Brickner <brickner@google.com>2024-10-14 14:06:50 +0200
committerGitHub <noreply@github.com>2024-10-14 14:06:50 +0200
commitc978f0f7ac33a5085053da7189201babd366c82d (patch)
tree15f651a370f74ee62cea1dc32d6c1c58c1464d82 /clang/lib/CodeGen/CodeGenModule.h
parent6a98c4a1602591c942f01dceb3aa29ffd4cf1e5b (diff)
downloadllvm-c978f0f7ac33a5085053da7189201babd366c82d.zip
llvm-c978f0f7ac33a5085053da7189201babd366c82d.tar.gz
llvm-c978f0f7ac33a5085053da7189201babd366c82d.tar.bz2
[clang] Fix segmentation fault caused by stack overflow on deeply nested expressions (#111701)
Done by calling clang::runWithSufficientStackSpace(). Added CodeGenModule::runWithSufficientStackSpace() method similar to the one in Sema to provide a single warning when this triggers Fixes: #111699
Diffstat (limited to 'clang/lib/CodeGen/CodeGenModule.h')
-rw-r--r--clang/lib/CodeGen/CodeGenModule.h11
1 files changed, 11 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.h b/clang/lib/CodeGen/CodeGenModule.h
index c58bb88..57e06cb 100644
--- a/clang/lib/CodeGen/CodeGenModule.h
+++ b/clang/lib/CodeGen/CodeGenModule.h
@@ -336,6 +336,7 @@ private:
std::unique_ptr<llvm::IndexedInstrProfReader> PGOReader;
InstrProfStats PGOStats;
std::unique_ptr<llvm::SanitizerStatReport> SanStats;
+ bool WarnedStackExhausted = false;
// A set of references that have only been seen via a weakref so far. This is
// used to remove the weak of the reference if we ever see a direct reference
@@ -1297,6 +1298,16 @@ public:
/// Print out an error that codegen doesn't support the specified decl yet.
void ErrorUnsupported(const Decl *D, const char *Type);
+ /// Warn that the stack is nearly exhausted.
+ void warnStackExhausted(SourceLocation Loc);
+
+ /// Run some code with "sufficient" stack space. (Currently, at least 256K is
+ /// guaranteed). Produces a warning if we're low on stack space and allocates
+ /// more in that case. Use this in code that may recurse deeply to avoid stack
+ /// overflow.
+ void runWithSufficientStackSpace(SourceLocation Loc,
+ llvm::function_ref<void()> Fn);
+
/// Set the attributes on the LLVM function for the given decl and function
/// info. This applies attributes necessary for handling the ABI as well as
/// user specified attributes like section.