[PATCH] D130422: [clang-repl] Fix incorrect return code
Jun Zhang via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sun Jul 31 02:11:33 PDT 2022
junaire updated this revision to Diff 448846.
junaire added a comment.
Fix some typos
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D130422/new/
https://reviews.llvm.org/D130422
Files:
clang/test/Interpreter/fail.cpp
clang/tools/clang-repl/ClangRepl.cpp
Index: clang/tools/clang-repl/ClangRepl.cpp
===================================================================
--- clang/tools/clang-repl/ClangRepl.cpp
+++ clang/tools/clang-repl/ClangRepl.cpp
@@ -50,7 +50,7 @@
// If we are running with -verify a reported has to be returned as unsuccess.
// This is relevant especially for the test suite.
-static int checkDiagErrors(const clang::CompilerInstance *CI) {
+static int checkDiagErrors(const clang::CompilerInstance *CI, bool HasError) {
unsigned Errs = CI->getDiagnostics().getClient()->getNumErrors();
if (CI->getDiagnosticOpts().VerifyDiagnostics) {
// If there was an error that came from the verifier we must return 1 as
@@ -62,7 +62,7 @@
// The interpreter expects BeginSourceFile/EndSourceFiles to be balanced.
Client->BeginSourceFile(CI->getLangOpts(), &CI->getPreprocessor());
}
- return Errs ? EXIT_FAILURE : EXIT_SUCCESS;
+ return (Errs || HasError) ? EXIT_FAILURE : EXIT_SUCCESS;
}
llvm::ExitOnError ExitOnErr;
@@ -107,6 +107,8 @@
llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(), "error: ");
}
+ bool HasError = false;
+
if (OptInputs.empty()) {
llvm::LineEditor LE("clang-repl");
// FIXME: Add LE.setListCompleter
@@ -114,13 +116,17 @@
if (*Line == R"(%quit)")
break;
if (*Line == R"(%undo)") {
- if (auto Err = Interp->Undo())
+ if (auto Err = Interp->Undo()) {
llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(), "error: ");
+ HasError = true;
+ }
continue;
}
- if (auto Err = Interp->ParseAndExecute(*Line))
+ if (auto Err = Interp->ParseAndExecute(*Line)) {
llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(), "error: ");
+ HasError = true;
+ }
}
}
@@ -129,5 +135,7 @@
// later errors use the default handling behavior instead.
llvm::remove_fatal_error_handler();
- return checkDiagErrors(Interp->getCompilerInstance());
+ llvm::llvm_shutdown();
+
+ return checkDiagErrors(Interp->getCompilerInstance(), HasError);
}
Index: clang/test/Interpreter/fail.cpp
===================================================================
--- /dev/null
+++ clang/test/Interpreter/fail.cpp
@@ -0,0 +1,17 @@
+// FIXME: There're some inconsistencies between interactive and non-interactive
+// modes. For example, when clang-repl runs in the interactive mode, issues an
+// error, and then successfully recovers if we decide it's a success then for
+// the non-interactive mode the exit code should be a failure.
+// RUN: clang-repl "int x = 10;" "int y=7; err;" "int y = 10;"
+// RUN: clang-repl "int i = 10;" 'extern "C" int printf(const char*,...);' \
+// RUN: 'auto r1 = printf("i = %d\n", i);' | FileCheck --check-prefix=CHECK-DRIVER %s
+// REQUIRES: host-supports-jit
+// UNSUPPORTED: system-aix
+// CHECK-DRIVER: i = 10
+// RUN: cat %s | not clang-repl | FileCheck %s
+BOOM!
+extern "C" int printf(const char *, ...);
+int i = 42;
+auto r1 = printf("i = %d\n", i);
+// CHECK: i = 42
+%quit
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D130422.448846.patch
Type: text/x-patch
Size: 3071 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220731/4e14a7bd/attachment-0001.bin>
More information about the cfe-commits
mailing list