Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions clang/test/Interpreter/out-of-process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

extern "C" int printf(const char *, ...);

printf("FLUSH_START");
// CHECK: FLUSH_START
printf("\nFLUSH_OK\n");
// CHECK: FLUSH_OK

int intVar = 0;
double doubleVar = 3.14;
%undo
Expand Down Expand Up @@ -85,4 +90,7 @@ int complexFunc(int x) \
auto r11 = printf("complexFunc(5) = %d\n", complexFunc(5));
// CHECK: complexFunc(5) = 15

printf("FINAL_FLUSH");
// CHECK: FINAL_FLUSH

%quit
14 changes: 14 additions & 0 deletions clang/tools/clang-repl/ClangRepl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,20 @@ int main(int argc, const char **argv) {
Interp = ExitOnErr(clang::Interpreter::create(std::move(CI), Config));
}

if (Config.IsOutOfProcess) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we condition this on out-of-process?
I am not sure, asking for an opinion.

I guess I am fine with everything else.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, removing the condition would introduce some consistency (otherwise oop is maintaining 1 more PTU .... PTU#2 after the inital runtime).

static const char *const InitUnbufferedStreams = R"(
#include <stdio.h>
__attribute__((constructor))
static void __clang_repl_ioinit(void) {
setvbuf(stdout, NULL, _IONBF, 0);
setvbuf(stderr, NULL, _IONBF, 0);
}
)";

if (auto Err = Interp->ParseAndExecute(InitUnbufferedStreams))
llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(), "error: ");
}

bool HasError = false;

for (const std::string &input : OptInputs) {
Expand Down
Loading