Skip to content

Commit c1c120d

Browse files
committed
[interop] Add required cling transactions to prevent crashes in GetNamed and GetAllCppNames
1 parent 4564944 commit c1c120d

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

interpreter/CppInterOp/lib/CppInterOp/CppInterOp.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -731,13 +731,17 @@ TCppScope_t GetNamed(const std::string& name,
731731
auto* D = (clang::Decl*)parent;
732732
D = GetUnderlyingScope(D);
733733
Within = llvm::dyn_cast<clang::DeclContext>(D);
734+
Within->getPrimaryContext()->buildLookup();
735+
// Within->buildLookup();
734736
}
735-
737+
#ifdef CPPINTEROP_USE_CLING
738+
cling::Interpreter::PushTransactionRAII RAII(&getInterp());
739+
#endif
736740
auto* ND = Cpp_utils::Lookup::Named(&getSema(), name, Within);
741+
737742
if (ND && ND != (clang::NamedDecl*)-1) {
738743
return (TCppScope_t)(ND->getCanonicalDecl());
739744
}
740-
741745
return 0;
742746
}
743747

@@ -3741,6 +3745,9 @@ void GetAllCppNames(TCppScope_t scope, std::set<std::string>& names) {
37413745
clang::DeclContext* DC;
37423746
clang::DeclContext::decl_iterator decl;
37433747

3748+
#ifdef CPPINTEROP_USE_CLING
3749+
cling::Interpreter::PushTransactionRAII RAII(&getInterp());
3750+
#endif
37443751
if (auto* TD = dyn_cast_or_null<TagDecl>(D)) {
37453752
DC = clang::TagDecl::castToDeclContext(TD);
37463753
decl = DC->decls_begin();

0 commit comments

Comments
 (0)