Skip to content

Commit fee6829

Browse files
Add executor explicit init patch
1 parent 023cab5 commit fee6829

File tree

3 files changed

+24
-9
lines changed

3 files changed

+24
-9
lines changed

clang/lib/Interpreter/Interpreter.cpp

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,12 +231,24 @@ IncrementalCompilerBuilder::CreateCudaHost() {
231231
}
232232

233233
Interpreter::Interpreter(std::unique_ptr<CompilerInstance> CI,
234-
llvm::Error &Err) {
235-
llvm::ErrorAsOutParameter EAO(&Err);
234+
llvm::Error &ErrOut) {
235+
llvm::ErrorAsOutParameter EAO(&ErrOut);
236236
auto LLVMCtx = std::make_unique<llvm::LLVMContext>();
237237
TSCtx = std::make_unique<llvm::orc::ThreadSafeContext>(std::move(LLVMCtx));
238-
IncrParser = std::make_unique<IncrementalParser>(*this, std::move(CI),
239-
*TSCtx->getContext(), Err);
238+
IncrParser = std::make_unique<IncrementalParser>(
239+
*this, std::move(CI), *TSCtx->getContext(), ErrOut);
240+
if (llvm::Error Err = CreateExecutor()) {
241+
ErrOut = joinErrors(std::move(ErrOut), std::move(Err));
242+
return;
243+
}
244+
245+
// Process the PTUs that came from initialization. For example -include will
246+
// give us a header that's processed at initialization of the preprocessor.
247+
for (PartialTranslationUnit &PTU : IncrParser->getPTUs())
248+
if (llvm::Error Err = Execute(PTU)) {
249+
ErrOut = joinErrors(std::move(ErrOut), std::move(Err));
250+
return;
251+
}
240252
}
241253

242254
Interpreter::~Interpreter() {
@@ -386,6 +398,10 @@ llvm::Error Interpreter::CreateExecutor() {
386398
return llvm::make_error<llvm::StringError>("Operation failed. "
387399
"Execution engine exists",
388400
std::error_code());
401+
if (!IncrParser->getCodeGen())
402+
return llvm::make_error<llvm::StringError>("Operation failed. "
403+
"No code generator available",
404+
std::error_code());
389405
llvm::Error Err = llvm::Error::success();
390406
auto Executor = std::make_unique<IncrementalExecutor>(*TSCtx, Err, TI);
391407
if (!Err)

clang/test/Interpreter/execute.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
// RUN: cat %s | clang-repl | FileCheck %s
99
// RUN: cat %s | clang-repl -Xcc -O2 | FileCheck %s
10+
// RUN: clang-repl -Xcc -include -Xcc %s | FileCheck %s
11+
// RUN: clang-repl -Xcc -fsyntax-only -Xcc -include -Xcc %s
1012
extern "C" int printf(const char *, ...);
1113
int i = 42;
1214
auto r1 = printf("i = %d\n", i);
@@ -19,5 +21,3 @@ auto r2 = printf("S[f=%f, m=0x%llx]\n", s.f, reinterpret_cast<unsigned long long
1921

2022
inline int foo() { return 42; }
2123
int r3 = foo();
22-
23-
%quit

clang/unittests/Interpreter/InterpreterExtensionsTest.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@ class TestCreateResetExecutor : public Interpreter {
3333
llvm::Error &Err)
3434
: Interpreter(std::move(CI), Err) {}
3535

36-
llvm::Error testCreateExecutor() {
37-
return Interpreter::CreateExecutor();
38-
}
36+
llvm::Error testCreateExecutor() { return Interpreter::CreateExecutor(); }
3937

4038
void resetExecutor() { Interpreter::ResetExecutor(); }
4139
};
@@ -45,6 +43,7 @@ TEST(InterpreterExtensionsTest, ExecutorCreateReset) {
4543
llvm::Error ErrOut = llvm::Error::success();
4644
TestCreateResetExecutor Interp(cantFail(CB.CreateCpp()), ErrOut);
4745
cantFail(std::move(ErrOut));
46+
Interp.resetExecutor();
4847
cantFail(Interp.testCreateExecutor());
4948
Interp.resetExecutor();
5049
cantFail(Interp.testCreateExecutor());

0 commit comments

Comments
 (0)