[clang] [clang-repl] Fix the process return code if diagnostics occurred. (PR #89879)
Vassil Vassilev via cfe-commits
cfe-commits at lists.llvm.org
Tue Apr 23 23:32:56 PDT 2024
https://github.com/vgvassilev updated https://github.com/llvm/llvm-project/pull/89879
>From d6b3d2a7b93399f8e895118e9f43378a2efa21f1 Mon Sep 17 00:00:00 2001
From: Vassil Vassilev <v.g.vassilev at gmail.com>
Date: Wed, 24 Apr 2024 06:30:55 +0000
Subject: [PATCH] [clang-repl] Fix the process return code if diagnostics
occurred.
---
clang/test/Interpreter/fail.cpp | 11 ++++-------
clang/tools/clang-repl/ClangRepl.cpp | 17 +++++++----------
2 files changed, 11 insertions(+), 17 deletions(-)
diff --git a/clang/test/Interpreter/fail.cpp b/clang/test/Interpreter/fail.cpp
index 4e301f37548f1f..b9035aca3cb7b1 100644
--- a/clang/test/Interpreter/fail.cpp
+++ b/clang/test/Interpreter/fail.cpp
@@ -1,12 +1,9 @@
-// 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;"
// REQUIRES: host-supports-jit
// UNSUPPORTED: system-aix
-// RUN: cat %s | not clang-repl | FileCheck %s
-BOOM!
+// RUN: not clang-repl "int x = 10;" "int y=7; err;" "int y = 10;"
+// RUN: cat %s | clang-repl | FileCheck %s
+// RUN: cat %s | not clang-repl -Xcc -Xclang -Xcc -verify | FileCheck %s
+BOOM! // expected-error {{intended to fail the -verify test}}
extern "C" int printf(const char *, ...);
int i = 42;
auto r1 = printf("i = %d\n", i);
diff --git a/clang/tools/clang-repl/ClangRepl.cpp b/clang/tools/clang-repl/ClangRepl.cpp
index aecf61b97fc719..9cfc70462893dd 100644
--- a/clang/tools/clang-repl/ClangRepl.cpp
+++ b/clang/tools/clang-repl/ClangRepl.cpp
@@ -215,13 +215,15 @@ int main(int argc, const char **argv) {
} else
Interp = ExitOnErr(clang::Interpreter::create(std::move(CI)));
+ bool HasError = false;
+
for (const std::string &input : OptInputs) {
- if (auto Err = Interp->ParseAndExecute(input))
+ if (auto Err = Interp->ParseAndExecute(input)) {
llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(), "error: ");
+ HasError = true;
+ }
}
- bool HasError = false;
-
if (OptInputs.empty()) {
llvm::LineEditor LE("clang-repl");
std::string Input;
@@ -241,18 +243,13 @@ int main(int argc, const char **argv) {
break;
}
if (Input == R"(%undo)") {
- if (auto Err = Interp->Undo()) {
+ if (auto Err = Interp->Undo())
llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(), "error: ");
- HasError = true;
- }
} else if (Input.rfind("%lib ", 0) == 0) {
- if (auto Err = Interp->LoadDynamicLibrary(Input.data() + 5)) {
+ if (auto Err = Interp->LoadDynamicLibrary(Input.data() + 5))
llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(), "error: ");
- HasError = true;
- }
} else if (auto Err = Interp->ParseAndExecute(Input)) {
llvm::logAllUnhandledErrors(std::move(Err), llvm::errs(), "error: ");
- HasError = true;
}
Input = "";
More information about the cfe-commits
mailing list