diff --git a/core/metacling/src/TCling.cxx b/core/metacling/src/TCling.cxx index 0b99545b6d58a..4e8a49d6c0d14 100644 --- a/core/metacling/src/TCling.cxx +++ b/core/metacling/src/TCling.cxx @@ -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; } @@ -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. @@ -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(); @@ -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) @@ -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" diff --git a/core/metacling/src/TClingCallbacks.cxx b/core/metacling/src/TClingCallbacks.cxx index c537c9edbea74..5a034cc5bdcac 100644 --- a/core/metacling/src/TClingCallbacks.cxx +++ b/core/metacling/src/TClingCallbacks.cxx @@ -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