Skip to content

Commit

Permalink
fix error handling when parsing invaild code
Browse files Browse the repository at this point in the history
llvm::Error need to be consumed before destructor
  • Loading branch information
Vipul-Cariappa authored and jenkins committed Dec 1, 2024
1 parent d9adac0 commit f55adaf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
12 changes: 8 additions & 4 deletions lib/Interpreter/IncrementalParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <stdio.h>
Expand Down Expand Up @@ -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:
Expand All @@ -939,7 +943,7 @@ namespace cling {
return kSuccess;
}

llvm::Expected<bool> IncrementalParser::ParseOrWrapTopLevelDecl() {
llvm::Error IncrementalParser::ParseOrWrapTopLevelDecl() {
// Recover resources if we crash before exiting this method.
Sema& S = getCI()->getSema();
DiagnosticsEngine& Diags = getCI()->getDiagnostics();
Expand Down Expand Up @@ -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.
Expand All @@ -1005,7 +1009,7 @@ namespace cling {
LocalInstantiations.perform();
GlobalInstantiations.perform();

return true;
return llvm::Error::success();
}

void IncrementalParser::printTransactionStructure() const {
Expand Down
3 changes: 2 additions & 1 deletion lib/Interpreter/IncrementalParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <vector>
#include <deque>
Expand Down Expand Up @@ -253,7 +254,7 @@ namespace cling {
///
EParseResult ParseInternal(llvm::StringRef input);

llvm::Expected<bool> ParseOrWrapTopLevelDecl();
llvm::Error ParseOrWrapTopLevelDecl();

///\brief Create a unique name for the next llvm::Module
///
Expand Down

0 comments on commit f55adaf

Please sign in to comment.