diff options
author | Younan Zhang <zyn7109@gmail.com> | 2023-08-28 14:51:59 +0800 |
---|---|---|
committer | Younan Zhang <zyn7109@gmail.com> | 2023-09-02 18:53:06 +0800 |
commit | e257c0a9190637e44e292271103a13d70bec4b03 (patch) | |
tree | ca8b0d4ec01046e224b9e9d8ba2aabacce3d19d0 /clang/lib/Frontend/FrontendAction.cpp | |
parent | 208f9a2afcc9882c2eebe0c00d296bd1226de103 (diff) | |
download | llvm-e257c0a9190637e44e292271103a13d70bec4b03.zip llvm-e257c0a9190637e44e292271103a13d70bec4b03.tar.gz llvm-e257c0a9190637e44e292271103a13d70bec4b03.tar.bz2 |
[clang][clangd] Ensure the stack bottom before building AST
`clang::runWithSufficientStackSpace` requires the address of the
initial stack bottom to prevent potential stack overflows.
In addition, add a fallback to ASTFrontendAction in case any client
forgets to call it when not through CompilerInstance::ExecuteAction,
which is rare.
Fixes https://github.com/clangd/clangd/issues/1745.
Reviewed By: sammccall
Differential Revision: https://reviews.llvm.org/D158967
Diffstat (limited to 'clang/lib/Frontend/FrontendAction.cpp')
-rw-r--r-- | clang/lib/Frontend/FrontendAction.cpp | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/clang/lib/Frontend/FrontendAction.cpp b/clang/lib/Frontend/FrontendAction.cpp index f14557c..2da25be 100644 --- a/clang/lib/Frontend/FrontendAction.cpp +++ b/clang/lib/Frontend/FrontendAction.cpp @@ -15,6 +15,7 @@ #include "clang/Basic/FileEntry.h" #include "clang/Basic/LangStandard.h" #include "clang/Basic/Sarif.h" +#include "clang/Basic/Stack.h" #include "clang/Frontend/ASTUnit.h" #include "clang/Frontend/CompilerInstance.h" #include "clang/Frontend/FrontendDiagnostic.h" @@ -1155,6 +1156,10 @@ void ASTFrontendAction::ExecuteAction() { CompilerInstance &CI = getCompilerInstance(); if (!CI.hasPreprocessor()) return; + // This is a fallback: If the client forgets to invoke this, we mark the + // current stack as the bottom. Though not optimal, this could help prevent + // stack overflow during deep recursion. + clang::noteBottomOfStack(); // FIXME: Move the truncation aspect of this into Sema, we delayed this till // here so the source manager would be initialized. |