Author: Aaron Danen Date: 2025-07-23T10:13:11+01:00 New Revision: c295f050633ba4feb3e2ed74811b9c9d7add758d
URL: https://github.com/llvm/llvm-project/commit/c295f050633ba4feb3e2ed74811b9c9d7add758d DIFF: https://github.com/llvm/llvm-project/commit/c295f050633ba4feb3e2ed74811b9c9d7add758d.diff LOG: [clang-repl] Improve error message on failed undos (#149396) Updated error message logic for undo function. Throws different errors for the case of there being nothing to undo, and for the case of requesting more undos than there are operations to undo. Fixes https://github.com/llvm/llvm-project/issues/143668 Added: Modified: clang/lib/Interpreter/Interpreter.cpp clang/unittests/Interpreter/InterpreterTest.cpp Removed: ################################################################################ diff --git a/clang/lib/Interpreter/Interpreter.cpp b/clang/lib/Interpreter/Interpreter.cpp index db6a2bb914f43..9b714860c4145 100644 --- a/clang/lib/Interpreter/Interpreter.cpp +++ b/clang/lib/Interpreter/Interpreter.cpp @@ -761,10 +761,18 @@ 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. " - "Too many undos", + "No input left to undo", 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()), + std::error_code()); + } + for (unsigned I = 0; I < N; I++) { if (IncrExecutor) { if (llvm::Error Err = IncrExecutor->removeModule(PTUs.back())) diff --git a/clang/unittests/Interpreter/InterpreterTest.cpp b/clang/unittests/Interpreter/InterpreterTest.cpp index 2ba15cbd37093..768058b954d49 100644 --- a/clang/unittests/Interpreter/InterpreterTest.cpp +++ b/clang/unittests/Interpreter/InterpreterTest.cpp @@ -160,12 +160,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. Wanted to undo 2 inputs, only have 1.", llvm::toString(std::move(Err3))); // Succeed to undo. _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits