diff options
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/Basic/LangOptions.cpp | 1 | ||||
-rw-r--r-- | clang/lib/Driver/Tools.cpp | 2 | ||||
-rw-r--r-- | clang/lib/Frontend/ASTUnit.cpp | 2 | ||||
-rw-r--r-- | clang/lib/Frontend/CompilerInstance.cpp | 10 | ||||
-rw-r--r-- | clang/lib/Frontend/CompilerInvocation.cpp | 10 | ||||
-rw-r--r-- | clang/lib/Frontend/FrontendActions.cpp | 2 | ||||
-rw-r--r-- | clang/lib/Lex/ModuleMap.cpp | 29 | ||||
-rw-r--r-- | clang/lib/Lex/PPDirectives.cpp | 37 | ||||
-rw-r--r-- | clang/lib/Lex/PPMacroExpansion.cpp | 5 | ||||
-rw-r--r-- | clang/lib/Lex/Preprocessor.cpp | 2 | ||||
-rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 19 | ||||
-rw-r--r-- | clang/lib/Sema/SemaDeclObjC.cpp | 2 |
12 files changed, 50 insertions, 71 deletions
diff --git a/clang/lib/Basic/LangOptions.cpp b/clang/lib/Basic/LangOptions.cpp index 1b08b068604..8c0ecd46ad5 100644 --- a/clang/lib/Basic/LangOptions.cpp +++ b/clang/lib/Basic/LangOptions.cpp @@ -34,7 +34,6 @@ void LangOptions::resetNonModularOptions() { SanitizerBlacklistFiles.clear(); CurrentModule.clear(); - ImplementationOfModule.clear(); } bool LangOptions::isNoBuiltinFunc(const char *Name) const { diff --git a/clang/lib/Driver/Tools.cpp b/clang/lib/Driver/Tools.cpp index 8441a91a637..584dfed5a45 100644 --- a/clang/lib/Driver/Tools.cpp +++ b/clang/lib/Driver/Tools.cpp @@ -4909,7 +4909,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, // -fmodule-name specifies the module that is currently being built (or // used for header checking by -fmodule-maps). - Args.AddLastArg(CmdArgs, options::OPT_fmodule_name); + Args.AddLastArg(CmdArgs, options::OPT_fmodule_name_EQ); // -fmodule-map-file can be used to specify files containing module // definitions. diff --git a/clang/lib/Frontend/ASTUnit.cpp b/clang/lib/Frontend/ASTUnit.cpp index 54ac6048bc1..0080fab13e2 100644 --- a/clang/lib/Frontend/ASTUnit.cpp +++ b/clang/lib/Frontend/ASTUnit.cpp @@ -2814,7 +2814,7 @@ const FileEntry *ASTUnit::getPCHFile() { } bool ASTUnit::isModuleFile() { - return isMainFileAST() && !ASTFileLangOpts.CurrentModule.empty(); + return isMainFileAST() && ASTFileLangOpts.CompilingModule; } void ASTUnit::PreambleData::countLines() const { diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index 2b940ce360c..04a4c7dbe68 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -1386,8 +1386,7 @@ CompilerInstance::loadModule(SourceLocation ImportLoc, // when both the preprocessor and parser see the same import declaration. if (ImportLoc.isValid() && LastModuleImportLoc == ImportLoc) { // Make the named module visible. - if (LastModuleImportResult && ModuleName != getLangOpts().CurrentModule && - ModuleName != getLangOpts().ImplementationOfModule) + if (LastModuleImportResult && ModuleName != getLangOpts().CurrentModule) ModuleManager->makeModuleVisible(LastModuleImportResult, Visibility, ImportLoc); return LastModuleImportResult; @@ -1401,8 +1400,7 @@ CompilerInstance::loadModule(SourceLocation ImportLoc, if (Known != KnownModules.end()) { // Retrieve the cached top-level module. Module = Known->second; - } else if (ModuleName == getLangOpts().CurrentModule || - ModuleName == getLangOpts().ImplementationOfModule) { + } else if (ModuleName == getLangOpts().CurrentModule) { // This is the module we're building. Module = PP->getHeaderSearchInfo().lookupModule(ModuleName); Known = KnownModules.insert(std::make_pair(Path[0].first, Module)).first; @@ -1580,10 +1578,6 @@ CompilerInstance::loadModule(SourceLocation ImportLoc, } } - // Don't make the module visible if we are in the implementation. - if (ModuleName == getLangOpts().ImplementationOfModule) - return ModuleLoadResult(Module, false); - // Make the named module visible, if it's not already part of the module // we are parsing. if (ModuleName != getLangOpts().CurrentModule) { diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index c822bccaa3c..2e0822794ee 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -1763,10 +1763,8 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK, Opts.DebuggerCastResultToId = Args.hasArg(OPT_fdebugger_cast_result_to_id); Opts.DebuggerObjCLiteral = Args.hasArg(OPT_fdebugger_objc_literal); Opts.ApplePragmaPack = Args.hasArg(OPT_fapple_pragma_pack); - Opts.CurrentModule = Args.getLastArgValue(OPT_fmodule_name); + Opts.CurrentModule = Args.getLastArgValue(OPT_fmodule_name_EQ); Opts.AppExt = Args.hasArg(OPT_fapplication_extension); - Opts.ImplementationOfModule = - Args.getLastArgValue(OPT_fmodule_implementation_of); Opts.ModuleFeatures = Args.getAllArgValues(OPT_fmodule_feature); std::sort(Opts.ModuleFeatures.begin(), Opts.ModuleFeatures.end()); Opts.NativeHalfType |= Args.hasArg(OPT_fnative_half_type); @@ -1784,12 +1782,6 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK, Args.hasFlag(OPT_fdeclspec, OPT_fno_declspec, (Opts.MicrosoftExt || Opts.Borland || Opts.CUDA)); - if (!Opts.CurrentModule.empty() && !Opts.ImplementationOfModule.empty() && - Opts.CurrentModule != Opts.ImplementationOfModule) { - Diags.Report(diag::err_conflicting_module_names) - << Opts.CurrentModule << Opts.ImplementationOfModule; - } - // For now, we only support local submodule visibility in C++ (because we // heavily depend on the ODR for merging redefinitions). if (Opts.ModulesLocalVisibility && !Opts.CPlusPlus) diff --git a/clang/lib/Frontend/FrontendActions.cpp b/clang/lib/Frontend/FrontendActions.cpp index 060055fe115..6f76aa0992d 100644 --- a/clang/lib/Frontend/FrontendActions.cpp +++ b/clang/lib/Frontend/FrontendActions.cpp @@ -270,6 +270,8 @@ collectModuleHeaderIncludes(const LangOptions &LangOpts, FileManager &FileMgr, bool GenerateModuleAction::BeginSourceFileAction(CompilerInstance &CI, StringRef Filename) { + CI.getLangOpts().CompilingModule = true; + // Find the module map file. const FileEntry *ModuleMap = CI.getFileManager().getFile(Filename, /*openFile*/true); diff --git a/clang/lib/Lex/ModuleMap.cpp b/clang/lib/Lex/ModuleMap.cpp index f39928a44a8..1c5b4e2f1ad 100644 --- a/clang/lib/Lex/ModuleMap.cpp +++ b/clang/lib/Lex/ModuleMap.cpp @@ -89,7 +89,7 @@ ModuleMap::ModuleMap(SourceManager &SourceMgr, DiagnosticsEngine &Diags, HeaderSearch &HeaderInfo) : SourceMgr(SourceMgr), Diags(Diags), LangOpts(LangOpts), Target(Target), HeaderInfo(HeaderInfo), BuiltinIncludeDir(nullptr), - CompilingModule(nullptr), SourceModule(nullptr), NumCreatedModules(0) { + SourceModule(nullptr), NumCreatedModules(0) { MMapLangOpts.LineComment = true; } @@ -343,8 +343,8 @@ ModuleMap::KnownHeader ModuleMap::findModuleForHeader(const FileEntry *File) { ModuleMap::KnownHeader Result; // Iterate over all modules that 'File' is part of to find the best fit. for (KnownHeader &H : Known->second) { - // Prefer a header from the current module over all others. - if (H.getModule()->getTopLevelModule() == CompilingModule) + // Prefer a header from the source module over all others. + if (H.getModule()->getTopLevelModule() == SourceModule) return MakeResult(H); if (!Result || isBetterKnownHeader(H, Result)) Result = H; @@ -556,16 +556,10 @@ ModuleMap::findOrCreateModule(StringRef Name, Module *Parent, bool IsFramework, // Create a new module with this name. Module *Result = new Module(Name, SourceLocation(), Parent, IsFramework, IsExplicit, NumCreatedModules++); - if (LangOpts.CurrentModule == Name) { - SourceModule = Result; - SourceModuleName = Name; - } if (!Parent) { + if (LangOpts.CurrentModule == Name) + SourceModule = Result; Modules[Name] = Result; - if (!LangOpts.CurrentModule.empty() && !CompilingModule && - Name == LangOpts.CurrentModule) { - CompilingModule = Result; - } } return std::make_pair(Result, true); } @@ -693,9 +687,10 @@ Module *ModuleMap::inferFrameworkModule(const DirectoryEntry *FrameworkDir, NumCreatedModules++); InferredModuleAllowedBy[Result] = ModuleMapFile; Result->IsInferred = true; - if (LangOpts.CurrentModule == ModuleName) { - SourceModule = Result; - SourceModuleName = ModuleName; + if (!Parent) { + if (LangOpts.CurrentModule == ModuleName) + SourceModule = Result; + Modules[ModuleName] = Result; } Result->IsSystem |= Attrs.IsSystem; @@ -703,9 +698,6 @@ Module *ModuleMap::inferFrameworkModule(const DirectoryEntry *FrameworkDir, Result->ConfigMacrosExhaustive |= Attrs.IsExhaustive; Result->Directory = FrameworkDir; - if (!Parent) - Modules[ModuleName] = Result; - // umbrella header "umbrella-header-name" // // The "Headers/" component of the name is implied because this is @@ -812,7 +804,8 @@ void ModuleMap::addHeader(Module *Mod, Module::Header Header, HeaderList.push_back(KH); Mod->Headers[headerRoleToKind(Role)].push_back(std::move(Header)); - bool isCompilingModuleHeader = Mod->getTopLevelModule() == CompilingModule; + bool isCompilingModuleHeader = + LangOpts.CompilingModule && Mod->getTopLevelModule() == SourceModule; if (!Imported || isCompilingModuleHeader) { // When we import HeaderFileInfo, the external source is expected to // set the isModuleHeader flag itself. diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp index 645d0903617..320c16dbec2 100644 --- a/clang/lib/Lex/PPDirectives.cpp +++ b/clang/lib/Lex/PPDirectives.cpp @@ -573,23 +573,23 @@ void Preprocessor::PTHSkipExcludedConditionalBlock() { } Module *Preprocessor::getModuleForLocation(SourceLocation Loc) { - ModuleMap &ModMap = HeaderInfo.getModuleMap(); - if (SourceMgr.isInMainFile(Loc)) { - if (Module *CurMod = getCurrentModule()) - return CurMod; // Compiling a module. - return HeaderInfo.getModuleMap().SourceModule; // Compiling a source. - } - // Try to determine the module of the include directive. - // FIXME: Look into directly passing the FileEntry from LookupFile instead. - FileID IDOfIncl = SourceMgr.getFileID(SourceMgr.getExpansionLoc(Loc)); - if (const FileEntry *EntryOfIncl = SourceMgr.getFileEntryForID(IDOfIncl)) { - // The include comes from a file. - return ModMap.findModuleForHeader(EntryOfIncl).getModule(); - } else { - // The include does not come from a file, - // so it is probably a module compilation. - return getCurrentModule(); + if (!SourceMgr.isInMainFile(Loc)) { + // Try to determine the module of the include directive. + // FIXME: Look into directly passing the FileEntry from LookupFile instead. + FileID IDOfIncl = SourceMgr.getFileID(SourceMgr.getExpansionLoc(Loc)); + if (const FileEntry *EntryOfIncl = SourceMgr.getFileEntryForID(IDOfIncl)) { + // The include comes from an included file. + return HeaderInfo.getModuleMap() + .findModuleForHeader(EntryOfIncl) + .getModule(); + } } + + // This is either in the main file or not in a file at all. It belongs + // to the current module, if there is one. + return getLangOpts().CurrentModule.empty() + ? nullptr + : HeaderInfo.lookupModule(getLangOpts().CurrentModule); } Module *Preprocessor::getModuleContainingLocation(SourceLocation Loc) { @@ -1668,10 +1668,7 @@ void Preprocessor::HandleIncludeDirective(SourceLocation HashLoc, // are processing this module textually (because we're building the module). if (File && SuggestedModule && getLangOpts().Modules && SuggestedModule.getModule()->getTopLevelModuleName() != - getLangOpts().CurrentModule && - SuggestedModule.getModule()->getTopLevelModuleName() != - getLangOpts().ImplementationOfModule) { - + getLangOpts().CurrentModule) { // If this include corresponds to a module but that module is // unavailable, diagnose the situation and bail out. if (!SuggestedModule.getModule()->isAvailable()) { diff --git a/clang/lib/Lex/PPMacroExpansion.cpp b/clang/lib/Lex/PPMacroExpansion.cpp index 69f5bc8ddcc..a47b356f9c0 100644 --- a/clang/lib/Lex/PPMacroExpansion.cpp +++ b/clang/lib/Lex/PPMacroExpansion.cpp @@ -1438,8 +1438,9 @@ static bool EvaluateBuildingModule(Token &Tok, return false; } - bool Result - = Tok.getIdentifierInfo()->getName() == PP.getLangOpts().CurrentModule; + bool Result = + PP.getLangOpts().CompilingModule && + Tok.getIdentifierInfo()->getName() == PP.getLangOpts().CurrentModule; // Get ')'. PP.LexNonComment(Tok); diff --git a/clang/lib/Lex/Preprocessor.cpp b/clang/lib/Lex/Preprocessor.cpp index 142d9ce0904..70b992170c9 100644 --- a/clang/lib/Lex/Preprocessor.cpp +++ b/clang/lib/Lex/Preprocessor.cpp @@ -477,7 +477,7 @@ void Preprocessor::CreateString(StringRef Str, Token &Tok, } Module *Preprocessor::getCurrentModule() { - if (getLangOpts().CurrentModule.empty()) + if (!getLangOpts().CompilingModule) return nullptr; return getHeaderSearchInfo().lookupModule(getLangOpts().CurrentModule); diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index d79e2e287f2..62cd5c8e3db 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -14752,11 +14752,10 @@ DeclResult Sema::ActOnModuleImport(SourceLocation AtLoc, // of the same top-level module. Until we do, make it an error rather than // silently ignoring the import. if (Mod->getTopLevelModuleName() == getLangOpts().CurrentModule) - Diag(ImportLoc, diag::err_module_self_import) + Diag(ImportLoc, getLangOpts().CompilingModule + ? diag::err_module_self_import + : diag::err_module_import_in_implementation) << Mod->getFullModuleName() << getLangOpts().CurrentModule; - else if (Mod->getTopLevelModuleName() == getLangOpts().ImplementationOfModule) - Diag(ImportLoc, diag::err_module_import_in_implementation) - << Mod->getFullModuleName() << getLangOpts().ImplementationOfModule; SmallVector<SourceLocation, 2> IdentifierLocs; Module *ModCheck = Mod; @@ -14790,11 +14789,13 @@ void Sema::ActOnModuleInclude(SourceLocation DirectiveLoc, Module *Mod) { TUKind == TU_Module && getSourceManager().isWrittenInMainFile(DirectiveLoc); - // Similarly, if this module is specified by -fmodule-implementation-of - // don't actually synthesize an illegal module import. - bool ShouldAddImport = !IsInModuleIncludes && - (getLangOpts().ImplementationOfModule.empty() || - getLangOpts().ImplementationOfModule != Mod->getTopLevelModuleName()); + // Similarly, if we're in the implementation of a module, don't + // synthesize an illegal module import. FIXME: Why not? + bool ShouldAddImport = + !IsInModuleIncludes && + (getLangOpts().CompilingModule || + getLangOpts().CurrentModule.empty() || + getLangOpts().CurrentModule != Mod->getTopLevelModuleName()); // If this module import was due to an inclusion directive, create an // implicit import declaration to capture it in the AST. diff --git a/clang/lib/Sema/SemaDeclObjC.cpp b/clang/lib/Sema/SemaDeclObjC.cpp index 89d99906a07..6121973eb18 100644 --- a/clang/lib/Sema/SemaDeclObjC.cpp +++ b/clang/lib/Sema/SemaDeclObjC.cpp @@ -3171,7 +3171,7 @@ void Sema::addMethodToGlobalList(ObjCMethodList *List, ObjCMethodList *Previous = List; for (; List; Previous = List, List = List->getNext()) { // If we are building a module, keep all of the methods. - if (getLangOpts().Modules && !getLangOpts().CurrentModule.empty()) + if (getLangOpts().CompilingModule) continue; if (!MatchTwoMethodDeclarations(Method, List->getMethod())) { |