Skip to content

Commit 75b36d0

Browse files
authored
[clang-repl] Put CompilerInstance from IncrementalAction to use for non-assert/assert builds (#155400)
See #137458 (comment) 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); ```
1 parent d5c5ed3 commit 75b36d0

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

clang/lib/Interpreter/IncrementalAction.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,25 @@
2222
#include "llvm/Support/ErrorHandling.h"
2323

2424
namespace clang {
25-
IncrementalAction::IncrementalAction(CompilerInstance &CI,
25+
IncrementalAction::IncrementalAction(CompilerInstance &Instance,
2626
llvm::LLVMContext &LLVMCtx,
2727
llvm::Error &Err, Interpreter &I,
2828
std::unique_ptr<ASTConsumer> Consumer)
2929
: WrapperFrontendAction([&]() {
3030
llvm::ErrorAsOutParameter EAO(&Err);
3131
std::unique_ptr<FrontendAction> Act;
32-
switch (CI.getFrontendOpts().ProgramAction) {
32+
switch (Instance.getFrontendOpts().ProgramAction) {
3333
default:
3434
Err = llvm::createStringError(
3535
std::errc::state_not_recoverable,
3636
"Driver initialization failed. "
3737
"Incremental mode for action %d is not supported",
38-
CI.getFrontendOpts().ProgramAction);
38+
Instance.getFrontendOpts().ProgramAction);
3939
return Act;
4040
case frontend::ASTDump:
4141
case frontend::ASTPrint:
4242
case frontend::ParseSyntaxOnly:
43-
Act = CreateFrontendAction(CI);
43+
Act = CreateFrontendAction(Instance);
4444
break;
4545
case frontend::PluginAction:
4646
case frontend::EmitAssembly:
@@ -53,12 +53,13 @@ IncrementalAction::IncrementalAction(CompilerInstance &CI,
5353
}
5454
return Act;
5555
}()),
56-
Interp(I), CI(CI), Consumer(std::move(Consumer)) {}
56+
Interp(I), CI(Instance), Consumer(std::move(Consumer)) {}
5757

5858
std::unique_ptr<ASTConsumer>
59-
IncrementalAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) {
59+
IncrementalAction::CreateASTConsumer(CompilerInstance & /*CI*/,
60+
StringRef InFile) {
6061
std::unique_ptr<ASTConsumer> C =
61-
WrapperFrontendAction::CreateASTConsumer(CI, InFile);
62+
WrapperFrontendAction::CreateASTConsumer(this->CI, InFile);
6263

6364
if (Consumer) {
6465
std::vector<std::unique_ptr<ASTConsumer>> Cs;
@@ -148,4 +149,4 @@ bool InProcessPrintingASTConsumer::HandleTopLevelDecl(DeclGroupRef DGR) {
148149
return MultiplexConsumer::HandleTopLevelDecl(DGR);
149150
}
150151

151-
} // namespace clang
152+
} // namespace clang

clang/lib/Interpreter/IncrementalAction.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class IncrementalAction : public WrapperFrontendAction {
4242
std::unique_ptr<llvm::Module> CachedInCodeGenModule;
4343

4444
public:
45-
IncrementalAction(CompilerInstance &CI, llvm::LLVMContext &LLVMCtx,
45+
IncrementalAction(CompilerInstance &Instance, llvm::LLVMContext &LLVMCtx,
4646
llvm::Error &Err, Interpreter &I,
4747
std::unique_ptr<ASTConsumer> Consumer = nullptr);
4848

0 commit comments

Comments
 (0)