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("Operation failed. " - "Too many undos", + "No input left to undo", std::error_code()); + } else if (N > getEffectivePTUSize()) { + return llvm::make_error( + 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.