Skip to content

Commit d6b3d2a

Browse files
committed
[clang-repl] Fix the process return code if diagnostics occurred.
1 parent 05c1447 commit d6b3d2a

File tree

2 files changed

+11
-17
lines changed

2 files changed

+11
-17
lines changed

clang/test/Interpreter/fail.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
// FIXME: There're some inconsistencies between interactive and non-interactive
2-
// modes. For example, when clang-repl runs in the interactive mode, issues an
3-
// error, and then successfully recovers if we decide it's a success then for
4-
// the non-interactive mode the exit code should be a failure.
5-
// RUN: clang-repl "int x = 10;" "int y=7; err;" "int y = 10;"
61
// REQUIRES: host-supports-jit
72
// UNSUPPORTED: system-aix
8-
// RUN: cat %s | not clang-repl | FileCheck %s
9-
BOOM!
3+
// RUN: not clang-repl "int x = 10;" "int y=7; err;" "int y = 10;"
4+
// RUN: cat %s | clang-repl | FileCheck %s
5+
// RUN: cat %s | not clang-repl -Xcc -Xclang -Xcc -verify | FileCheck %s
6+
BOOM! // expected-error {{intended to fail the -verify test}}
107
extern "C" int printf(const char *, ...);
118
int i = 42;
129
auto r1 = printf("i = %d\n", i);

clang/tools/clang-repl/ClangRepl.cpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -215,13 +215,15 @@ int main(int argc, const char **argv) {
215215
} else
216216
Interp = ExitOnErr(clang::Interpreter::create(std::move(CI)));
217217

218+
bool HasError = false;
219+
218220
for (const std::string &input : OptInputs) {
219-
if (auto Err = Interp->ParseAndExecute(input))
221+
if (auto Err = Interp->ParseAndExecute(input)) {
220222
llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(), "error: ");
223+
HasError = true;
224+
}
221225
}
222226

223-
bool HasError = false;
224-
225227
if (OptInputs.empty()) {
226228
llvm::LineEditor LE("clang-repl");
227229
std::string Input;
@@ -241,18 +243,13 @@ int main(int argc, const char **argv) {
241243
break;
242244
}
243245
if (Input == R"(%undo)") {
244-
if (auto Err = Interp->Undo()) {
246+
if (auto Err = Interp->Undo())
245247
llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(), "error: ");
246-
HasError = true;
247-
}
248248
} else if (Input.rfind("%lib ", 0) == 0) {
249-
if (auto Err = Interp->LoadDynamicLibrary(Input.data() + 5)) {
249+
if (auto Err = Interp->LoadDynamicLibrary(Input.data() + 5))
250250
llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(), "error: ");
251-
HasError = true;
252-
}
253251
} else if (auto Err = Interp->ParseAndExecute(Input)) {
254252
llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(), "error: ");
255-
HasError = true;
256253
}
257254

258255
Input = "";

0 commit comments

Comments
 (0)