Skip to content
11 changes: 9 additions & 2 deletions clang/lib/Interpreter/Interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -761,10 +761,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. "
"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()))
Expand Down
4 changes: 2 additions & 2 deletions clang/unittests/Interpreter/InterpreterTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading