From 07e6c407bc67ed4f5fc88d2382df26bb7b3def4f Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Mon, 5 Aug 2013 20:26:17 +0000 Subject: [PATCH] Add option to disable module loading. This patch was created by Lawrence Crowl and reviewed in: http://llvm-reviews.chandlerc.com/D963 llvm-svn: 187738 --- clang/docs/Modules.rst | 5 +++++ clang/include/clang/Driver/Options.td | 5 +++++ clang/include/clang/Lex/HeaderSearchOptions.h | 5 ++++- clang/lib/Driver/Tools.cpp | 7 +++++++ clang/lib/Frontend/CompilerInvocation.cpp | 2 ++ clang/lib/Lex/PPDirectives.cpp | 21 ++++++++++++--------- clang/lib/Lex/Preprocessor.cpp | 2 +- clang/lib/Sema/SemaCodeComplete.cpp | 2 +- 8 files changed, 37 insertions(+), 12 deletions(-) diff --git a/clang/docs/Modules.rst b/clang/docs/Modules.rst index cd430a2..6ac334d 100644 --- a/clang/docs/Modules.rst +++ b/clang/docs/Modules.rst @@ -148,6 +148,8 @@ Module maps are specified as separate files (each named ``module.map``) alongsid .. note:: To actually see any benefits from modules, one first has to introduce module maps for the underlying C standard library and the libraries and headers on which it depends. The section `Modularizing a Platform`_ describes the steps one must take to write these module maps. + +One can use module maps without modules to check the integrity of the use of header files. To do this, use the ``-fmodule-maps`` option instead of the ``-fmodules`` option. Compilation model ----------------- @@ -165,6 +167,9 @@ Command-line parameters ``-fcxx-modules`` Enable the modules feature for C++ (EXPERIMENTAL and VERY BROKEN). +``-fmodule-maps`` + Enable interpretation of module maps (EXPERIMENTAL). This option is implied by ``-fmodules``. + ``-fmodules-cache-path=`` Specify the path to the modules cache. If not provided, Clang will select a system-appropriate default. diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 28d9a5e..21f0417 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -557,6 +557,9 @@ def fmodules_prune_after : Joined<["-"], "fmodules-prune-after=">, Group, Group, Flags<[DriverOption, CC1Option]>, HelpText<"Enable the 'modules' language feature">; +def fmodule_maps : Flag <["-"], "fmodule-maps">, Group, + Flags<[DriverOption,CC1Option]>, + HelpText<"Read module maps to understand the structure of library headers">; def fmodules_ignore_macro : Joined<["-"], "fmodules-ignore-macro=">, Group, Flags<[CC1Option]>, HelpText<"Ignore the definition of the given macro when building and loading modules">; def fretain_comments_from_system_headers : Flag<["-"], "fretain-comments-from-system-headers">, Group, Flags<[CC1Option]>; @@ -617,6 +620,8 @@ def fno_merge_all_constants : Flag<["-"], "fno-merge-all-constants">, Group, HelpText<"Disallow merging of constants">; def fno_modules : Flag <["-"], "fno-modules">, Group, Flags<[DriverOption]>; +def fno_module_maps : Flag <["-"], "fno-module-maps">, Group, + Flags<[DriverOption]>; def fno_ms_extensions : Flag<["-"], "fno-ms-extensions">, Group; def fno_ms_compatibility : Flag<["-"], "fno-ms-compatibility">, Group; def fno_delayed_template_parsing : Flag<["-"], "fno-delayed-template-parsing">, Group; diff --git a/clang/include/clang/Lex/HeaderSearchOptions.h b/clang/include/clang/Lex/HeaderSearchOptions.h index afce5ba..830f48d 100644 --- a/clang/include/clang/Lex/HeaderSearchOptions.h +++ b/clang/include/clang/Lex/HeaderSearchOptions.h @@ -95,6 +95,9 @@ public: /// Note: Only used for testing! unsigned DisableModuleHash : 1; + /// \brief Interpret module maps. This option is implied by full modules. + unsigned ModuleMaps : 1; + /// \brief The interval (in seconds) between pruning operations. /// /// This operation is expensive, because it requires Clang to walk through @@ -134,7 +137,7 @@ public: public: HeaderSearchOptions(StringRef _Sysroot = "/") - : Sysroot(_Sysroot), DisableModuleHash(0), + : Sysroot(_Sysroot), DisableModuleHash(0), ModuleMaps(0), ModuleCachePruneInterval(7*24*60*60), ModuleCachePruneAfter(31*24*60*60), UseBuiltinIncludes(true), diff --git a/clang/lib/Driver/Tools.cpp b/clang/lib/Driver/Tools.cpp index dfaffaa..254bf8b 100644 --- a/clang/lib/Driver/Tools.cpp +++ b/clang/lib/Driver/Tools.cpp @@ -3070,6 +3070,13 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, } } + // -fmodule-maps enables module map processing (off by default) for header + // checking. It is implied by -fmodules. + if (Args.hasFlag(options::OPT_fmodule_maps, options::OPT_fno_module_maps, + false)) { + CmdArgs.push_back("-fmodule-maps"); + } + // If a module path was provided, pass it along. Otherwise, use a temporary // directory. if (Arg *A = Args.getLastArg(options::OPT_fmodules_cache_path)) { diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index d362e33..27ddd84 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -872,6 +872,8 @@ static void ParseHeaderSearchArgs(HeaderSearchOptions &Opts, ArgList &Args) { Opts.ResourceDir = Args.getLastArgValue(OPT_resource_dir); Opts.ModuleCachePath = Args.getLastArgValue(OPT_fmodules_cache_path); Opts.DisableModuleHash = Args.hasArg(OPT_fdisable_module_hash); + // -fmodules implies -fmodule-maps + Opts.ModuleMaps = Args.hasArg(OPT_fmodule_maps) || Args.hasArg(OPT_fmodules); Opts.ModuleCachePruneInterval = getLastArgIntValue(Args, OPT_fmodules_prune_interval, 7 * 24 * 60 * 60); Opts.ModuleCachePruneAfter = diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp index c70019f..ef0cbd6 100644 --- a/clang/lib/Lex/PPDirectives.cpp +++ b/clang/lib/Lex/PPDirectives.cpp @@ -17,6 +17,7 @@ #include "clang/Basic/SourceManager.h" #include "clang/Lex/CodeCompletionHandler.h" #include "clang/Lex/HeaderSearch.h" +#include "clang/Lex/HeaderSearchOptions.h" #include "clang/Lex/LexDiagnostic.h" #include "clang/Lex/LiteralSupport.h" #include "clang/Lex/MacroInfo.h" @@ -1421,7 +1422,7 @@ void Preprocessor::HandleIncludeDirective(SourceLocation HashLoc, const FileEntry *File = LookupFile( FilenameLoc, Filename, isAngled, LookupFrom, CurDir, Callbacks ? &SearchPath : NULL, Callbacks ? &RelativePath : NULL, - getLangOpts().Modules? &SuggestedModule : 0); + HeaderInfo.getHeaderSearchOpts().ModuleMaps ? &SuggestedModule : 0); if (Callbacks) { if (!File) { @@ -1435,13 +1436,15 @@ void Preprocessor::HandleIncludeDirective(SourceLocation HashLoc, // Try the lookup again, skipping the cache. File = LookupFile(FilenameLoc, Filename, isAngled, LookupFrom, CurDir, - 0, 0, getLangOpts().Modules? &SuggestedModule : 0, - /*SkipCache*/true); + 0, 0, HeaderInfo.getHeaderSearchOpts().ModuleMaps + ? &SuggestedModule + : 0, + /*SkipCache*/ true); } } } - if (!SuggestedModule) { + if (!SuggestedModule || !getLangOpts().Modules) { // Notify the callback object that we've seen an inclusion directive. Callbacks->InclusionDirective(HashLoc, IncludeTok, Filename, isAngled, FilenameRange, File, @@ -1456,10 +1459,10 @@ void Preprocessor::HandleIncludeDirective(SourceLocation HashLoc, // brackets, we can attempt a lookup as though it were a quoted path to // provide the user with a possible fixit. if (isAngled) { - File = LookupFile(FilenameLoc, Filename, false, LookupFrom, CurDir, - Callbacks ? &SearchPath : 0, - Callbacks ? &RelativePath : 0, - getLangOpts().Modules ? &SuggestedModule : 0); + File = LookupFile( + FilenameLoc, Filename, false, LookupFrom, CurDir, + Callbacks ? &SearchPath : 0, Callbacks ? &RelativePath : 0, + HeaderInfo.getHeaderSearchOpts().ModuleMaps ? &SuggestedModule : 0); if (File) { SourceRange Range(FilenameTok.getLocation(), CharEnd); Diag(FilenameTok, diag::err_pp_file_not_found_not_fatal) << @@ -1477,7 +1480,7 @@ void Preprocessor::HandleIncludeDirective(SourceLocation HashLoc, // If we are supposed to import a module rather than including the header, // do so now. - if (SuggestedModule) { + if (SuggestedModule && getLangOpts().Modules) { // Compute the module access path corresponding to this module. // FIXME: Should we have a second loadModule() overload to avoid this // extra lookup step? diff --git a/clang/lib/Lex/Preprocessor.cpp b/clang/lib/Lex/Preprocessor.cpp index 66f23f1..035f751 100644 --- a/clang/lib/Lex/Preprocessor.cpp +++ b/clang/lib/Lex/Preprocessor.cpp @@ -734,7 +734,7 @@ void Preprocessor::LexAfterModuleImport(Token &Result) { } // If we have a non-empty module path, load the named module. - if (!ModuleImportPath.empty()) { + if (!ModuleImportPath.empty() && getLangOpts().Modules) { Module *Imported = TheModuleLoader.loadModule(ModuleImportLoc, ModuleImportPath, Module::MacrosVisible, diff --git a/clang/lib/Sema/SemaCodeComplete.cpp b/clang/lib/Sema/SemaCodeComplete.cpp index b46392b..bf57597 100644 --- a/clang/lib/Sema/SemaCodeComplete.cpp +++ b/clang/lib/Sema/SemaCodeComplete.cpp @@ -3188,7 +3188,7 @@ void Sema::CodeCompleteModuleImport(SourceLocation ImportLoc, ? CXAvailability_Available : CXAvailability_NotAvailable)); } - } else { + } else if (getLangOpts().Modules) { // Load the named module. Module *Mod = PP.getModuleLoader().loadModule(ImportLoc, Path, Module::AllVisible, -- 2.7.4