From 2255f2ce90777f5a614e98840e57250816743b15 Mon Sep 17 00:00:00 2001 From: John Thompson Date: Wed, 23 Apr 2014 12:57:01 +0000 Subject: Initial implementation of -modules-earch-all option, for searching for symbols in non-imported modules. llvm-svn: 206977 --- clang/docs/Modules.rst | 3 + clang/include/clang/Basic/LangOptions.def | 1 + clang/include/clang/Driver/Options.td | 5 + clang/include/clang/Frontend/ASTUnit.h | 2 + clang/include/clang/Frontend/CompilerInstance.h | 9 +- clang/include/clang/Lex/HeaderSearch.h | 1 - clang/include/clang/Lex/ModuleLoader.h | 29 ++++- clang/include/clang/Sema/Sema.h | 6 + clang/include/clang/Serialization/ASTReader.h | 7 ++ clang/lib/Frontend/CompilerInstance.cpp | 139 +++++++++++++++------ clang/lib/Frontend/CompilerInvocation.cpp | 3 + clang/lib/Sema/SemaCXXScopeSpec.cpp | 3 +- clang/lib/Sema/SemaDecl.cpp | 15 ++- clang/lib/Sema/SemaDeclCXX.cpp | 8 +- clang/lib/Sema/SemaDeclObjC.cpp | 7 +- clang/lib/Sema/SemaExpr.cpp | 5 +- clang/lib/Sema/SemaExprMember.cpp | 6 +- clang/lib/Sema/SemaExprObjC.cpp | 5 +- clang/lib/Sema/SemaInit.cpp | 2 +- clang/lib/Sema/SemaLookup.cpp | 36 +++++- clang/lib/Sema/SemaOpenMP.cpp | 2 +- clang/lib/Sema/SemaTemplate.cpp | 3 +- clang/lib/Sema/SemaTemplateVariadic.cpp | 2 +- .../Modules/Inputs/undefined-type-fixit/module.map | 9 ++ .../Modules/Inputs/undefined-type-fixit/public1.h | 6 + .../Modules/Inputs/undefined-type-fixit/public2.h | 6 + .../Inputs/undefined-type-fixit/public2sub.h | 6 + clang/test/Modules/undefined-type-fixit1.cpp | 12 ++ clang/unittests/Basic/SourceManagerTest.cpp | 3 + clang/unittests/Lex/CMakeLists.txt | 1 + clang/unittests/Lex/LexerTest.cpp | 3 + clang/unittests/Lex/Makefile | 4 +- clang/unittests/Lex/PPCallbacksTest.cpp | 3 + .../Lex/PPConditionalDirectiveRecordTest.cpp | 3 + 34 files changed, 287 insertions(+), 68 deletions(-) create mode 100644 clang/test/Modules/Inputs/undefined-type-fixit/module.map create mode 100644 clang/test/Modules/Inputs/undefined-type-fixit/public1.h create mode 100644 clang/test/Modules/Inputs/undefined-type-fixit/public2.h create mode 100644 clang/test/Modules/Inputs/undefined-type-fixit/public2sub.h create mode 100644 clang/test/Modules/undefined-type-fixit1.cpp diff --git a/clang/docs/Modules.rst b/clang/docs/Modules.rst index 59daebcc936..ce1e717bc2a 100644 --- a/clang/docs/Modules.rst +++ b/clang/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/clang/include/clang/Basic/LangOptions.def b/clang/include/clang/Basic/LangOptions.def index 3295ca4a278..699bf1fa4d3 100644 --- a/clang/include/clang/Basic/LangOptions.def +++ b/clang/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/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index b734280a891..d6b22795e0e 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/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<"