Skip to content

Commit 78c1624

Browse files
Vipul-Cariappavgvassilev
authored andcommitted
[cling] fix error handling when parsing invaild code
llvm::Error need to be consumed before destructor
1 parent 790fdfa commit 78c1624

2 files changed

Lines changed: 10 additions & 5 deletions

File tree

interpreter/cling/lib/Interpreter/IncrementalParser.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
#include "llvm/IR/LLVMContext.h"
5454
#include "llvm/IR/Module.h"
5555
#include "llvm/Support/CrashRecoveryContext.h"
56+
#include "llvm/Support/Error.h"
5657
#include "llvm/Support/MemoryBuffer.h"
5758

5859
#include <stdio.h>
@@ -911,8 +912,11 @@ namespace cling {
911912
PP.EnterSourceFile(FID, /*DirLookup*/nullptr, NewLoc);
912913
m_Consumer->getTransaction()->setBufferFID(FID);
913914

914-
if (!ParseOrWrapTopLevelDecl())
915+
llvm::Error res = ParseOrWrapTopLevelDecl();
916+
if (res) {
917+
llvm::consumeError(std::move(res));
915918
return kFailed;
919+
}
916920

917921
if (PP.getLangOpts().DelayedTemplateParsing) {
918922
// Microsoft-specific:
@@ -939,7 +943,7 @@ namespace cling {
939943
return kSuccess;
940944
}
941945

942-
llvm::Expected<bool> IncrementalParser::ParseOrWrapTopLevelDecl() {
946+
llvm::Error IncrementalParser::ParseOrWrapTopLevelDecl() {
943947
// Recover resources if we crash before exiting this method.
944948
Sema& S = getCI()->getSema();
945949
DiagnosticsEngine& Diags = getCI()->getDiagnostics();
@@ -993,7 +997,7 @@ namespace cling {
993997
// Let's ignore this transaction:
994998
m_Consumer->getTransaction()->setIssuedDiags(Transaction::kErrors);
995999

996-
return true;
1000+
return llvm::Error::success();
9971001
}
9981002

9991003
// Process any TopLevelDecls generated by #pragma weak.
@@ -1005,7 +1009,7 @@ namespace cling {
10051009
LocalInstantiations.perform();
10061010
GlobalInstantiations.perform();
10071011

1008-
return true;
1012+
return llvm::Error::success();
10091013
}
10101014

10111015
void IncrementalParser::printTransactionStructure() const {

interpreter/cling/lib/Interpreter/IncrementalParser.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "llvm/ADT/PointerIntPair.h"
1616
#include "llvm/ADT/SmallVector.h"
1717
#include "llvm/ADT/StringRef.h"
18+
#include "llvm/Support/Error.h"
1819

1920
#include <vector>
2021
#include <deque>
@@ -253,7 +254,7 @@ namespace cling {
253254
///
254255
EParseResult ParseInternal(llvm::StringRef input);
255256

256-
llvm::Expected<bool> ParseOrWrapTopLevelDecl();
257+
llvm::Error ParseOrWrapTopLevelDecl();
257258

258259
///\brief Create a unique name for the next llvm::Module
259260
///

0 commit comments

Comments
 (0)