Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 20 additions & 9 deletions core/metacling/src/TCling.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1098,17 +1098,14 @@ static bool LoadModule(const std::string &ModuleName, cling::Interpreter &interp
clang::HeaderSearch &headerSearch = PP.getHeaderSearchInfo();
clang::ModuleMap &moduleMap = headerSearch.getModuleMap();

cling::Transaction* T = nullptr;
interp.declare("/*This is decl is to get a valid sloc...*/;", &T);
SourceLocation ValidLoc = T->decls_begin()->m_DGR.getSingleDecl()->getLocStart();
// CreateImplicitModuleImportNoInit creates decls.
cling::Interpreter::PushTransactionRAII RAII(&interp);
if (clang::Module *M = moduleMap.findModule(ModuleName)) {
clang::IdentifierInfo *II = PP.getIdentifierInfo(M->Name);
bool Result = !CI.getSema().ActOnModuleImport(ValidLoc, ValidLoc, std::make_pair(II, ValidLoc)).isInvalid();
SourceLocation ValidLoc = M->DefinitionLoc;
bool success = !CI.getSema().ActOnModuleImport(ValidLoc, ValidLoc, std::make_pair(II, ValidLoc)).isInvalid();
// Also make the module visible in the preprocessor to export its macros.
PP.makeModuleVisible(M, ValidLoc);
return Result;
return success;
}
return false;
}
Expand Down Expand Up @@ -1927,6 +1924,20 @@ void TCling::RegisterModule(const char* modulename,

clang::Sema &TheSema = fInterpreter->getSema();

bool ModuleWasSuccessfullyLoaded = false;
if (TheSema.getLangOpts().Modules) {
std::string ModuleName = llvm::StringRef(modulename).substr(3).str();
ModuleWasSuccessfullyLoaded = LoadModule(ModuleName, *fInterpreter);
if (!ModuleWasSuccessfullyLoaded) {
// Only report if we found the module in the modulemap.
clang::Preprocessor &PP = TheSema.getPreprocessor();
clang::HeaderSearch &headerSearch = PP.getHeaderSearchInfo();
clang::ModuleMap &moduleMap = headerSearch.getModuleMap();
if (moduleMap.findModule(ModuleName))
Info("TCling::RegisterModule", "Module %s in modulemap failed to load.", ModuleName.c_str());
}
}

{ // scope within which diagnostics are de-activated
// For now we disable diagnostics because we saw them already at
// dictionary generation time. That won't be an issue with the PCMs.
Expand All @@ -1939,7 +1950,7 @@ void TCling::RegisterModule(const char* modulename,
#endif
#endif

if (!hasHeaderParsingOnDemand){
if (!ModuleWasSuccessfullyLoaded && !hasHeaderParsingOnDemand){
SuspendAutoParsing autoParseRaii(this);

const cling::Transaction* watermark = fInterpreter->getLastTransaction();
Expand All @@ -1962,7 +1973,7 @@ void TCling::RegisterModule(const char* modulename,
// make sure to 'reset' the TClass that have a class init in this module
// but already had their type information available (using information/header
// loaded from other modules or from class rules).
if (!hasHeaderParsingOnDemand) {
if (!ModuleWasSuccessfullyLoaded && !hasHeaderParsingOnDemand) {
// This code is likely to be superseded by the similar code in LoadPCM,
// and have been disabled, (inadvertently or awkwardly) by
// commit 7903f09f3beea69e82ffba29f59fb2d656a4fd54 (Refactor the routines used for header parsing on demand)
Expand All @@ -1989,7 +2000,7 @@ void TCling::RegisterModule(const char* modulename,
if (fClingCallbacks)
SetClassAutoloading(oldValue);

if (!hasHeaderParsingOnDemand) {
if (!ModuleWasSuccessfullyLoaded && !hasHeaderParsingOnDemand) {
// __ROOTCLING__ might be pulled in through PCH
fInterpreter->declare("#ifdef __ROOTCLING__\n"
"#undef __ROOTCLING__\n"
Expand Down
13 changes: 12 additions & 1 deletion core/metacling/src/TClingCallbacks.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,18 @@ void TClingCallbacks::InclusionDirective(clang::SourceLocation sLoc/*HashLoc*/,
const clang::FileEntry *FE,
llvm::StringRef /*SearchPath*/,
llvm::StringRef /*RelativePath*/,
const clang::Module * /*Imported*/) {
const clang::Module * Imported) {
// We found a module. Do not try to do anything else.
if (Imported) {
Sema &SemaR = m_Interpreter->getSema();
// FIXME: We should make the module visible at that point.
if (!SemaR.isModuleVisible(Imported))
ROOT::TMetaUtils::Info("TClingCallbacks::InclusionDirective",
"Module %s resolved but not visible!", Imported->Name.c_str());
else
return;
}

// Method called via Callbacks->InclusionDirective()
// in Preprocessor::HandleIncludeDirective(), invoked whenever an
// inclusion directive has been processed, and allowing us to try
Expand Down