Skip to content

Commit b2b82b4

Browse files
committed
Add required cling transactions when performing named lookups
In GetBaseClassOffset, GetVariableOffset, GetFunctionsUsingName, ExistsFunctionTemplate, GetClassTemplatedMethods, LookupDatamember also fold usages of `DeclContext::buildLookup` into `utils::Lookup::Named` to avoid repetition
1 parent 65b597d commit b2b82b4

2 files changed

Lines changed: 13 additions & 4 deletions

File tree

lib/CppInterOp/CppInterOp.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -785,10 +785,7 @@ TCppScope_t GetNamed(const std::string& name,
785785
D = GetUnderlyingScope(D);
786786
Within = llvm::dyn_cast<clang::DeclContext>(D);
787787
}
788-
#ifdef CPPINTEROP_USE_CLING
789-
if (Within)
790-
Within->getPrimaryContext()->buildLookup();
791-
#endif
788+
792789
compat::SynthesizingCodeRAII RAII(&getInterp());
793790
auto* ND = CppInternal::utils::Lookup::Named(&getSema(), name, Within);
794791
if (ND && ND != (clang::NamedDecl*)-1) {
@@ -918,6 +915,8 @@ int64_t GetBaseClassOffset(TCppScope_t derived, TCppScope_t base) {
918915

919916
assert(derived || base);
920917

918+
compat::SynthesizingCodeRAII RAII(&getInterp());
919+
921920
auto* DD = (Decl*)derived;
922921
auto* BD = (Decl*)base;
923922
if (!isa<CXXRecordDecl>(DD) || !isa<CXXRecordDecl>(BD))
@@ -1045,6 +1044,7 @@ std::vector<TCppFunction_t> GetFunctionsUsingName(TCppScope_t scope,
10451044
clang::LookupResult R(S, DName, SourceLocation(), Sema::LookupOrdinaryName,
10461045
RedeclarationKind::ForVisibleRedeclaration);
10471046

1047+
compat::SynthesizingCodeRAII RAII(&getInterp());
10481048
CppInternal::utils::Lookup::Named(&S, R, Decl::castToDeclContext(D));
10491049

10501050
if (R.empty())
@@ -1189,6 +1189,7 @@ bool ExistsFunctionTemplate(const std::string& name, TCppScope_t parent) {
11891189
Within = llvm::dyn_cast<DeclContext>(D);
11901190
}
11911191

1192+
compat::SynthesizingCodeRAII RAII(&getInterp());
11921193
auto* ND = CppInternal::utils::Lookup::Named(&getSema(), name, Within);
11931194

11941195
if ((intptr_t)ND == (intptr_t)0)
@@ -1234,6 +1235,8 @@ bool GetClassTemplatedMethods(const std::string& name, TCppScope_t parent,
12341235
clang::LookupResult R(S, DName, SourceLocation(), Sema::LookupOrdinaryName,
12351236
RedeclarationKind::ForVisibleRedeclaration);
12361237
auto* DC = clang::Decl::castToDeclContext(D);
1238+
1239+
compat::SynthesizingCodeRAII RAII(&getInterp());
12371240
CppInternal::utils::Lookup::Named(&S, R, DC);
12381241

12391242
if (R.getResultKind() == clang_LookupResult_Not_Found && funcs.empty())
@@ -1547,6 +1550,7 @@ TCppScope_t LookupDatamember(const std::string& name, TCppScope_t parent) {
15471550
Within = llvm::dyn_cast<clang::DeclContext>(D);
15481551
}
15491552

1553+
compat::SynthesizingCodeRAII RAII(&getInterp());
15501554
auto* ND = CppInternal::utils::Lookup::Named(&getSema(), name, Within);
15511555
if (ND && ND != (clang::NamedDecl*)-1) {
15521556
if (llvm::isa_and_nonnull<clang::FieldDecl>(ND)) {
@@ -1593,6 +1597,7 @@ intptr_t GetVariableOffset(compat::Interpreter& I, Decl* D,
15931597
return 0;
15941598

15951599
auto& C = I.getSema().getASTContext();
1600+
compat::SynthesizingCodeRAII RAII(&getInterp());
15961601

15971602
if (auto* FD = llvm::dyn_cast<FieldDecl>(D)) {
15981603
clang::RecordDecl* FieldParentRecordDecl = FD->getParent();

lib/CppInterOp/CppInterOpInterpreter.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ inline clang::NamespaceDecl* Namespace(clang::Sema* S, const char* Name,
9797

9898
inline void Named(clang::Sema* S, clang::LookupResult& R,
9999
const clang::DeclContext* Within = nullptr) {
100+
#ifdef CPPINTEROP_USE_CLING
101+
if (Within)
102+
Within->getPrimaryContext()->buildLookup();
103+
#endif
100104
R.suppressDiagnostics();
101105
if (!Within)
102106
S->LookupName(R, S->TUScope);

0 commit comments

Comments
 (0)