[clang] [clang-repl] Improve error message on failed undos (PR #149396)
Aaron Danen via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 22 16:59:12 PDT 2025
https://github.com/aadanen updated https://github.com/llvm/llvm-project/pull/149396
>From f3fbebdd6d940d36561ccf5177510095ba05077e Mon Sep 17 00:00:00 2001
From: Aaron Danen <aaron.danen at gmail.com>
Date: Wed, 16 Jul 2025 19:44:58 -0700
Subject: [PATCH 1/5] clarified %undo error msg in clang-repl
used grep -r "Too many undos" to locate all instances where the string
was mentioned. Changed the string to the suggestion in issue 143668
---
clang/lib/Interpreter/Interpreter.cpp | 2 +-
clang/unittests/Interpreter/InterpreterTest.cpp | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/clang/lib/Interpreter/Interpreter.cpp b/clang/lib/Interpreter/Interpreter.cpp
index ed3bae59a144c..a2696f78cb510 100644
--- a/clang/lib/Interpreter/Interpreter.cpp
+++ b/clang/lib/Interpreter/Interpreter.cpp
@@ -754,7 +754,7 @@ llvm::Error Interpreter::Undo(unsigned N) {
if (N > getEffectivePTUSize())
return llvm::make_error<llvm::StringError>("Operation failed. "
- "Too many undos",
+ "No input left to undo",
std::error_code());
for (unsigned I = 0; I < N; I++) {
if (IncrExecutor) {
diff --git a/clang/unittests/Interpreter/InterpreterTest.cpp b/clang/unittests/Interpreter/InterpreterTest.cpp
index b97f5ae17c9f0..2ec65e2a9b2ef 100644
--- a/clang/unittests/Interpreter/InterpreterTest.cpp
+++ b/clang/unittests/Interpreter/InterpreterTest.cpp
@@ -158,12 +158,12 @@ TEST_F(InterpreterTest, UndoCommand) {
// Fail to undo.
auto Err1 = Interp->Undo();
- EXPECT_EQ("Operation failed. Too many undos",
+ EXPECT_EQ("Operation failed. No input left to undo",
llvm::toString(std::move(Err1)));
auto Err2 = Interp->Parse("int foo = 42;");
EXPECT_TRUE(!!Err2);
auto Err3 = Interp->Undo(2);
- EXPECT_EQ("Operation failed. Too many undos",
+ EXPECT_EQ("Operation failed. No input left to undo",
llvm::toString(std::move(Err3)));
// Succeed to undo.
>From b0513a8a46e69b3d9753d6ada1ca8f71debc9fe3 Mon Sep 17 00:00:00 2001
From: Aaron Danen <aaron.danen at gmail.com>
Date: Fri, 18 Jul 2025 18:18:27 -0700
Subject: [PATCH 2/5] implemented contextual error msg
differentiate between the case of 0 inputs to undo and the case when
there are X inputs and Y requested undos but Y > X
---
clang/lib/Interpreter/Interpreter.cpp | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/clang/lib/Interpreter/Interpreter.cpp b/clang/lib/Interpreter/Interpreter.cpp
index a2696f78cb510..5b4b73fd6490c 100644
--- a/clang/lib/Interpreter/Interpreter.cpp
+++ b/clang/lib/Interpreter/Interpreter.cpp
@@ -752,10 +752,17 @@ Interpreter::getSymbolAddressFromLinkerName(llvm::StringRef Name) const {
llvm::Error Interpreter::Undo(unsigned N) {
- if (N > getEffectivePTUSize())
+ if (getEffectivePTUSize() == 0) {
return llvm::make_error<llvm::StringError>("Operation failed. "
"No input left to undo",
std::error_code());
+ } else if (N > getEffectivePTUSize()) {
+ return llvm::make_error<llvm::StringError>(
+ llvm::formatv("Wanted to undo {0} inputs, only have {1}.",
+ N, getEffectivePTUSize()),
+ std::error_code());
+ }
+
for (unsigned I = 0; I < N; I++) {
if (IncrExecutor) {
if (llvm::Error Err = IncrExecutor->removeModule(PTUs.back()))
>From 9d9416a5117579db26e2217dce2311171d158573 Mon Sep 17 00:00:00 2001
From: Aaron Danen <aaron.danen at gmail.com>
Date: Sun, 20 Jul 2025 14:07:56 -0700
Subject: [PATCH 3/5] Slight edit to error msg. Updated unit test.
---
clang/lib/Interpreter/Interpreter.cpp | 2 +-
clang/unittests/Interpreter/InterpreterTest.cpp | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/clang/lib/Interpreter/Interpreter.cpp b/clang/lib/Interpreter/Interpreter.cpp
index 5b4b73fd6490c..27af662c3c32f 100644
--- a/clang/lib/Interpreter/Interpreter.cpp
+++ b/clang/lib/Interpreter/Interpreter.cpp
@@ -758,7 +758,7 @@ llvm::Error Interpreter::Undo(unsigned N) {
std::error_code());
} else if (N > getEffectivePTUSize()) {
return llvm::make_error<llvm::StringError>(
- llvm::formatv("Wanted to undo {0} inputs, only have {1}.",
+ llvm::formatv("Operation failed. Wanted to undo {0} inputs, only have {1}.",
N, getEffectivePTUSize()),
std::error_code());
}
diff --git a/clang/unittests/Interpreter/InterpreterTest.cpp b/clang/unittests/Interpreter/InterpreterTest.cpp
index 2ec65e2a9b2ef..042aa99607fa8 100644
--- a/clang/unittests/Interpreter/InterpreterTest.cpp
+++ b/clang/unittests/Interpreter/InterpreterTest.cpp
@@ -163,7 +163,7 @@ TEST_F(InterpreterTest, UndoCommand) {
auto Err2 = Interp->Parse("int foo = 42;");
EXPECT_TRUE(!!Err2);
auto Err3 = Interp->Undo(2);
- EXPECT_EQ("Operation failed. No input left to undo",
+ EXPECT_EQ("Operation failed. Wanted to undo 2 inputs but only have 1.",
llvm::toString(std::move(Err3)));
// Succeed to undo.
>From d5280feeb39de4fade25bbf002774c6df6c51135 Mon Sep 17 00:00:00 2001
From: Aaron Danen <aaron.danen at gmail.com>
Date: Sun, 20 Jul 2025 16:45:03 -0700
Subject: [PATCH 4/5] lil type made me fail the tests
---
clang/unittests/Interpreter/InterpreterTest.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang/unittests/Interpreter/InterpreterTest.cpp b/clang/unittests/Interpreter/InterpreterTest.cpp
index 042aa99607fa8..fa7c773d2b5bd 100644
--- a/clang/unittests/Interpreter/InterpreterTest.cpp
+++ b/clang/unittests/Interpreter/InterpreterTest.cpp
@@ -163,7 +163,7 @@ TEST_F(InterpreterTest, UndoCommand) {
auto Err2 = Interp->Parse("int foo = 42;");
EXPECT_TRUE(!!Err2);
auto Err3 = Interp->Undo(2);
- EXPECT_EQ("Operation failed. Wanted to undo 2 inputs but only have 1.",
+ EXPECT_EQ("Operation failed. Wanted to undo 2 inputs, only have 1.",
llvm::toString(std::move(Err3)));
// Succeed to undo.
>From e86636dee9660299ba76a3c318233e963847c826 Mon Sep 17 00:00:00 2001
From: Aaron Danen <aaron.danen at gmail.com>
Date: Tue, 22 Jul 2025 15:48:45 -0700
Subject: [PATCH 5/5] formatting
---
clang/lib/Interpreter/Interpreter.cpp | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/clang/lib/Interpreter/Interpreter.cpp b/clang/lib/Interpreter/Interpreter.cpp
index 27af662c3c32f..f5e0b2cc35509 100644
--- a/clang/lib/Interpreter/Interpreter.cpp
+++ b/clang/lib/Interpreter/Interpreter.cpp
@@ -758,8 +758,9 @@ llvm::Error Interpreter::Undo(unsigned N) {
std::error_code());
} else if (N > getEffectivePTUSize()) {
return llvm::make_error<llvm::StringError>(
- llvm::formatv("Operation failed. Wanted to undo {0} inputs, only have {1}.",
- N, getEffectivePTUSize()),
+ llvm::formatv(
+ "Operation failed. Wanted to undo {0} inputs, only have {1}.", N,
+ getEffectivePTUSize()),
std::error_code());
}
More information about the cfe-commits
mailing list