[PATCH] D130422: [clang-repl] Fix incorrect return code
Jun Zhang via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sat Jul 23 06:22:39 PDT 2022
junaire created this revision.
junaire added a reviewer: v.g.vassilev.
Herald added a project: All.
junaire requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
Without this patch, clang-repl incorrectly pass some tests when there's
error occured.
Signed-off-by: Jun Zhang <jun at junz.org>
Repository:
rG LLVM Github Monorepo
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;
@@ -105,6 +105,8 @@
llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(), "error: ");
}
+ bool HasError = false;
+
if (OptInputs.empty()) {
llvm::LineEditor LE("clang-repl");
// FIXME: Add LE.setListCompleter
@@ -112,13 +114,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,5 @@
llvm::llvm_shutdown();
- return checkDiagErrors(Interp->getCompilerInstance());
+ return checkDiagErrors(Interp->getCompilerInstance(), HasError);
}
Index: clang/test/Interpreter/fail.cpp
===================================================================
--- /dev/null
+++ clang/test/Interpreter/fail.cpp
@@ -0,0 +1,14 @@
+// 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
+// XFAIL: *
+// CHECK-DRIVER: i = 10
+// RUN: cat %s | 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.447065.patch
Type: text/x-patch
Size: 2675 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220723/491cd035/attachment.bin>
More information about the cfe-commits
mailing list