diff --git a/lib/CppInterOp/CppInterOp.cpp b/lib/CppInterOp/CppInterOp.cpp index cb6dbacfe..1b9c42914 100644 --- a/lib/CppInterOp/CppInterOp.cpp +++ b/lib/CppInterOp/CppInterOp.cpp @@ -1024,10 +1024,7 @@ TCppScope_t GetNamed(const std::string& name, D = GetUnderlyingScope(D); Within = llvm::dyn_cast(D); } -#ifdef CPPINTEROP_USE_CLING - if (Within) - Within->getPrimaryContext()->buildLookup(); -#endif + compat::SynthesizingCodeRAII RAII(&getInterp()); auto* ND = CppInternal::utils::Lookup::Named(&getSema(), name, Within); if (ND && ND != (clang::NamedDecl*)-1) { @@ -1163,6 +1160,8 @@ int64_t GetBaseClassOffset(TCppScope_t derived, TCppScope_t base) { assert(derived || base); + compat::SynthesizingCodeRAII RAII(&getInterp()); + auto* DD = (Decl*)derived; auto* BD = (Decl*)base; if (!isa(DD) || !isa(BD)) @@ -1315,6 +1314,7 @@ std::vector GetFunctionsUsingName(TCppScope_t scope, clang::LookupResult R(S, DName, SourceLocation(), Sema::LookupOrdinaryName, RedeclarationKind::ForVisibleRedeclaration); + compat::SynthesizingCodeRAII RAII(&getInterp()); CppInternal::utils::Lookup::Named(&S, R, Decl::castToDeclContext(D)); if (R.empty()) @@ -1469,6 +1469,7 @@ bool ExistsFunctionTemplate(const std::string& name, TCppScope_t parent) { Within = llvm::dyn_cast(D); } + compat::SynthesizingCodeRAII RAII(&getInterp()); auto* ND = CppInternal::utils::Lookup::Named(&getSema(), name, Within); if ((intptr_t)ND == (intptr_t)0) @@ -1517,6 +1518,8 @@ bool GetClassTemplatedMethods(const std::string& name, TCppScope_t parent, clang::LookupResult R(S, DName, SourceLocation(), Sema::LookupOrdinaryName, RedeclarationKind::ForVisibleRedeclaration); auto* DC = clang::Decl::castToDeclContext(D); + + compat::SynthesizingCodeRAII RAII(&getInterp()); CppInternal::utils::Lookup::Named(&S, R, DC); if (R.getResultKind() == clang_LookupResult_Not_Found && funcs.empty()) @@ -1850,6 +1853,7 @@ TCppScope_t LookupDatamember(const std::string& name, TCppScope_t parent) { Within = llvm::dyn_cast(D); } + compat::SynthesizingCodeRAII RAII(&getInterp()); auto* ND = CppInternal::utils::Lookup::Named(&getSema(), name, Within); if (ND && ND != (clang::NamedDecl*)-1) { if (llvm::isa_and_nonnull(ND)) { @@ -1898,6 +1902,7 @@ intptr_t GetVariableOffset(compat::Interpreter& I, Decl* D, return 0; auto& C = I.getSema().getASTContext(); + compat::SynthesizingCodeRAII RAII(&getInterp()); if (auto* FD = llvm::dyn_cast(D)) { clang::RecordDecl* FieldParentRecordDecl = FD->getParent(); diff --git a/lib/CppInterOp/CppInterOpInterpreter.h b/lib/CppInterOp/CppInterOpInterpreter.h index 380e0b6dd..b8909f749 100644 --- a/lib/CppInterOp/CppInterOpInterpreter.h +++ b/lib/CppInterOp/CppInterOpInterpreter.h @@ -97,6 +97,8 @@ inline clang::NamespaceDecl* Namespace(clang::Sema* S, const char* Name, inline void Named(clang::Sema* S, clang::LookupResult& R, const clang::DeclContext* Within = nullptr) { + if (Within) + Within->getPrimaryContext()->buildLookup(); R.suppressDiagnostics(); if (!Within) S->LookupName(R, S->TUScope);