From f55adaf353efce27801e71724c657bca6c2af0e4 Mon Sep 17 00:00:00 2001 From: Vipul Cariappa Date: Sun, 1 Dec 2024 10:57:59 +0530 Subject: [PATCH] fix error handling when parsing invaild code llvm::Error need to be consumed before destructor --- lib/Interpreter/IncrementalParser.cpp | 12 ++++++++---- lib/Interpreter/IncrementalParser.h | 3 ++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/Interpreter/IncrementalParser.cpp b/lib/Interpreter/IncrementalParser.cpp index 58e2b56736..c37ea1a75e 100644 --- a/lib/Interpreter/IncrementalParser.cpp +++ b/lib/Interpreter/IncrementalParser.cpp @@ -53,6 +53,7 @@ #include "llvm/IR/LLVMContext.h" #include "llvm/IR/Module.h" #include "llvm/Support/CrashRecoveryContext.h" +#include "llvm/Support/Error.h" #include "llvm/Support/MemoryBuffer.h" #include @@ -911,8 +912,11 @@ namespace cling { PP.EnterSourceFile(FID, /*DirLookup*/nullptr, NewLoc); m_Consumer->getTransaction()->setBufferFID(FID); - if (!ParseOrWrapTopLevelDecl()) + llvm::Error res = ParseOrWrapTopLevelDecl(); + if (res) { + llvm::consumeError(std::move(res)); return kFailed; + } if (PP.getLangOpts().DelayedTemplateParsing) { // Microsoft-specific: @@ -939,7 +943,7 @@ namespace cling { return kSuccess; } - llvm::Expected IncrementalParser::ParseOrWrapTopLevelDecl() { + llvm::Error IncrementalParser::ParseOrWrapTopLevelDecl() { // Recover resources if we crash before exiting this method. Sema& S = getCI()->getSema(); DiagnosticsEngine& Diags = getCI()->getDiagnostics(); @@ -993,7 +997,7 @@ namespace cling { // Let's ignore this transaction: m_Consumer->getTransaction()->setIssuedDiags(Transaction::kErrors); - return true; + return llvm::Error::success(); } // Process any TopLevelDecls generated by #pragma weak. @@ -1005,7 +1009,7 @@ namespace cling { LocalInstantiations.perform(); GlobalInstantiations.perform(); - return true; + return llvm::Error::success(); } void IncrementalParser::printTransactionStructure() const { diff --git a/lib/Interpreter/IncrementalParser.h b/lib/Interpreter/IncrementalParser.h index 44b2bf0233..ddea651239 100644 --- a/lib/Interpreter/IncrementalParser.h +++ b/lib/Interpreter/IncrementalParser.h @@ -15,6 +15,7 @@ #include "llvm/ADT/PointerIntPair.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringRef.h" +#include "llvm/Support/Error.h" #include #include @@ -253,7 +254,7 @@ namespace cling { /// EParseResult ParseInternal(llvm::StringRef input); - llvm::Expected ParseOrWrapTopLevelDecl(); + llvm::Error ParseOrWrapTopLevelDecl(); ///\brief Create a unique name for the next llvm::Module ///