[clang] 75b36d0 - [clang-repl] Put CompilerInstance from IncrementalAction to use for non-assert/assert builds (#155400)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Aug 27 03:00:26 PDT 2025
Author: Anutosh Bhat
Date: 2025-08-27T15:30:23+05:30
New Revision: 75b36d043e9992ec7c52c7d17f989c09a76011c7
URL: https://github.com/llvm/llvm-project/commit/75b36d043e9992ec7c52c7d17f989c09a76011c7
DIFF: https://github.com/llvm/llvm-project/commit/75b36d043e9992ec7c52c7d17f989c09a76011c7.diff
LOG: [clang-repl] Put CompilerInstance from IncrementalAction to use for non-assert/assert builds (#155400)
See
https://github.com/llvm/llvm-project/pull/137458#discussion_r2300649286
Context: So the CompilerInstance CI being used with the Incremental
Action are tightly coupled in any case. Which means
the CI put to use while constructing the IncrementalAction
```
Act = TSCtx->withContextDo([&](llvm::LLVMContext *Ctx) {
return std::make_unique<IncrementalAction>(*CI, *Ctx, ErrOut, *this,
std::move(Consumer));
});
```
Is also the CI through which the we call `ExecuteAction` on `Act`
```
CI->ExecuteAction(*Act);
```
So we need to use CI as a member variable in IncrementalAction for
assert builds for
https://github.com/llvm/llvm-project/blob/bddac5eda9b7591e05ccdc86a5e86c592085f318/clang/lib/Interpreter/IncrementalAction.cpp#L97-L108
The same can be put to use for `CreateASTConsumer` too as all of these
are referring to the same CI
```
std::unique_ptr<ASTConsumer>
IncrementalAction::CreateASTConsumer(CompilerInstance & /*CI*/, StringRef InFile) {
std::unique_ptr<ASTConsumer> C =
WrapperFrontendAction::CreateASTConsumer(this->CI, InFile);
```
Added:
Modified:
clang/lib/Interpreter/IncrementalAction.cpp
clang/lib/Interpreter/IncrementalAction.h
Removed:
################################################################################
diff --git a/clang/lib/Interpreter/IncrementalAction.cpp b/clang/lib/Interpreter/IncrementalAction.cpp
index 67313a8cd2a8c..4d1bc4c59e851 100644
--- a/clang/lib/Interpreter/IncrementalAction.cpp
+++ b/clang/lib/Interpreter/IncrementalAction.cpp
@@ -22,25 +22,25 @@
#include "llvm/Support/ErrorHandling.h"
namespace clang {
-IncrementalAction::IncrementalAction(CompilerInstance &CI,
+IncrementalAction::IncrementalAction(CompilerInstance &Instance,
llvm::LLVMContext &LLVMCtx,
llvm::Error &Err, Interpreter &I,
std::unique_ptr<ASTConsumer> Consumer)
: WrapperFrontendAction([&]() {
llvm::ErrorAsOutParameter EAO(&Err);
std::unique_ptr<FrontendAction> Act;
- switch (CI.getFrontendOpts().ProgramAction) {
+ switch (Instance.getFrontendOpts().ProgramAction) {
default:
Err = llvm::createStringError(
std::errc::state_not_recoverable,
"Driver initialization failed. "
"Incremental mode for action %d is not supported",
- CI.getFrontendOpts().ProgramAction);
+ Instance.getFrontendOpts().ProgramAction);
return Act;
case frontend::ASTDump:
case frontend::ASTPrint:
case frontend::ParseSyntaxOnly:
- Act = CreateFrontendAction(CI);
+ Act = CreateFrontendAction(Instance);
break;
case frontend::PluginAction:
case frontend::EmitAssembly:
@@ -53,12 +53,13 @@ IncrementalAction::IncrementalAction(CompilerInstance &CI,
}
return Act;
}()),
- Interp(I), CI(CI), Consumer(std::move(Consumer)) {}
+ Interp(I), CI(Instance), Consumer(std::move(Consumer)) {}
std::unique_ptr<ASTConsumer>
-IncrementalAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) {
+IncrementalAction::CreateASTConsumer(CompilerInstance & /*CI*/,
+ StringRef InFile) {
std::unique_ptr<ASTConsumer> C =
- WrapperFrontendAction::CreateASTConsumer(CI, InFile);
+ WrapperFrontendAction::CreateASTConsumer(this->CI, InFile);
if (Consumer) {
std::vector<std::unique_ptr<ASTConsumer>> Cs;
@@ -148,4 +149,4 @@ bool InProcessPrintingASTConsumer::HandleTopLevelDecl(DeclGroupRef DGR) {
return MultiplexConsumer::HandleTopLevelDecl(DGR);
}
-} // namespace clang
\ No newline at end of file
+} // namespace clang
diff --git a/clang/lib/Interpreter/IncrementalAction.h b/clang/lib/Interpreter/IncrementalAction.h
index b9dd087f258de..725cdd0c27cf4 100644
--- a/clang/lib/Interpreter/IncrementalAction.h
+++ b/clang/lib/Interpreter/IncrementalAction.h
@@ -42,7 +42,7 @@ class IncrementalAction : public WrapperFrontendAction {
std::unique_ptr<llvm::Module> CachedInCodeGenModule;
public:
- IncrementalAction(CompilerInstance &CI, llvm::LLVMContext &LLVMCtx,
+ IncrementalAction(CompilerInstance &Instance, llvm::LLVMContext &LLVMCtx,
llvm::Error &Err, Interpreter &I,
std::unique_ptr<ASTConsumer> Consumer = nullptr);
More information about the cfe-commits
mailing list