From 9be87f878588e7ed414dbfa29805883cc9cbb885 Mon Sep 17 00:00:00 2001 From: John Thompson Date: Wed, 23 Apr 2014 12:57:01 +0000 Subject: [PATCH] Initial implementation of -modules-earch-all option, for searching for symbols in non-imported modules. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@206977 91177308-0d34-0410-b5e6-96231b3b80d8 --- docs/Modules.rst | 3 + include/clang/Basic/LangOptions.def | 1 + include/clang/Driver/Options.td | 5 + include/clang/Frontend/ASTUnit.h | 2 + include/clang/Frontend/CompilerInstance.h | 9 +- include/clang/Lex/HeaderSearch.h | 1 - include/clang/Lex/ModuleLoader.h | 29 +++- include/clang/Sema/Sema.h | 6 + include/clang/Serialization/ASTReader.h | 7 + lib/Frontend/CompilerInstance.cpp | 139 +++++++++++++----- lib/Frontend/CompilerInvocation.cpp | 3 + lib/Sema/SemaCXXScopeSpec.cpp | 3 +- lib/Sema/SemaDecl.cpp | 15 +- lib/Sema/SemaDeclCXX.cpp | 8 +- lib/Sema/SemaDeclObjC.cpp | 7 +- lib/Sema/SemaExpr.cpp | 5 +- lib/Sema/SemaExprMember.cpp | 6 +- lib/Sema/SemaExprObjC.cpp | 5 +- lib/Sema/SemaInit.cpp | 2 +- lib/Sema/SemaLookup.cpp | 36 ++++- lib/Sema/SemaOpenMP.cpp | 2 +- lib/Sema/SemaTemplate.cpp | 3 +- lib/Sema/SemaTemplateVariadic.cpp | 2 +- .../Inputs/undefined-type-fixit/module.map | 9 ++ .../Inputs/undefined-type-fixit/public1.h | 6 + .../Inputs/undefined-type-fixit/public2.h | 6 + .../Inputs/undefined-type-fixit/public2sub.h | 6 + test/Modules/undefined-type-fixit1.cpp | 12 ++ unittests/Basic/SourceManagerTest.cpp | 3 + unittests/Lex/CMakeLists.txt | 1 + unittests/Lex/LexerTest.cpp | 3 + unittests/Lex/Makefile | 4 +- unittests/Lex/PPCallbacksTest.cpp | 3 + .../Lex/PPConditionalDirectiveRecordTest.cpp | 3 + 34 files changed, 287 insertions(+), 68 deletions(-) create mode 100644 test/Modules/Inputs/undefined-type-fixit/module.map create mode 100644 test/Modules/Inputs/undefined-type-fixit/public1.h create mode 100644 test/Modules/Inputs/undefined-type-fixit/public2.h create mode 100644 test/Modules/Inputs/undefined-type-fixit/public2sub.h create mode 100644 test/Modules/undefined-type-fixit1.cpp diff --git a/docs/Modules.rst b/docs/Modules.rst index 59daebcc93..ce1e717bc2 100644 --- a/docs/Modules.rst +++ b/docs/Modules.rst @@ -198,6 +198,9 @@ Command-line parameters ``-fmodule-map-file=`` Load the given module map file if a header from its directory or one of its subdirectories is loaded. +``-fmodules-search-all`` + If a symbol is not found, search modules referenced in the current module maps but not imported for symbols, so the error message can reference the module by name. Note that if the global module index has not been built before, this might take some time as it needs to build all the modules. Note that this option doesn't apply in module builds, to avoid the recursion. + Module Semantics ================ diff --git a/include/clang/Basic/LangOptions.def b/include/clang/Basic/LangOptions.def index 3295ca4a27..699bf1fa4d 100644 --- a/include/clang/Basic/LangOptions.def +++ b/include/clang/Basic/LangOptions.def @@ -96,6 +96,7 @@ LANGOPT(MathErrno , 1, 1, "errno support for math functions") BENIGN_LANGOPT(HeinousExtensions , 1, 0, "Extensions that we really don't like and may be ripped out at any time") LANGOPT(Modules , 1, 0, "modules extension to C") LANGOPT(ModulesDeclUse , 1, 0, "require declaration of module uses") +LANGOPT(ModulesSearchAll , 1, 1, "search even non-imported modules to find unresolved references") LANGOPT(ModulesStrictDeclUse, 1, 0, "require declaration of module uses and all headers to be in modules") LANGOPT(Optimize , 1, 0, "__OPTIMIZE__ predefined macro") LANGOPT(OptimizeSize , 1, 0, "__OPTIMIZE_SIZE__ predefined macro") diff --git a/include/clang/Driver/Options.td b/include/clang/Driver/Options.td index b734280a89..d6b22795e0 100644 --- a/include/clang/Driver/Options.td +++ b/include/clang/Driver/Options.td @@ -583,6 +583,9 @@ def fmodules_prune_interval : Joined<["-"], "fmodules-prune-interval=">, Group">, HelpText<"Specify the interval (in seconds) after which a module file will be considered unused">; +def fmodules_search_all : Flag <["-"], "fmodules-search-all">, Group, + Flags<[DriverOption, CC1Option]>, + HelpText<"Search even non-imported modules to resolve references">; def fbuild_session_timestamp : Joined<["-"], "fbuild-session-timestamp=">, Group, Flags<[CC1Option]>, MetaVarName<"