diff options
author | Ben Langmuir <blangmuir@apple.com> | 2014-03-12 00:06:17 +0000 |
---|---|---|
committer | Ben Langmuir <blangmuir@apple.com> | 2014-03-12 00:06:17 +0000 |
commit | dcf73861a56ed4ea334a88b71b2f0ffd8d8f10bd (patch) | |
tree | 83d43bd771ccd7cdeb76e86dbebf503a5c3f3bd2 | |
parent | e8d69b7fc98d612afc74bab7eda457646fc06900 (diff) | |
download | bcm5719-llvm-dcf73861a56ed4ea334a88b71b2f0ffd8d8f10bd.tar.gz bcm5719-llvm-dcf73861a56ed4ea334a88b71b2f0ffd8d8f10bd.zip |
Add an option -fmodules-validate-system-headers
When enabled, always validate the system headers when loading a module.
The end result of this is that when these headers change, we will notice
and rebuild the module.
llvm-svn: 203630
-rw-r--r-- | clang/include/clang/Driver/Options.td | 3 | ||||
-rw-r--r-- | clang/include/clang/Lex/HeaderSearchOptions.h | 6 | ||||
-rw-r--r-- | clang/lib/Driver/Tools.cpp | 2 | ||||
-rw-r--r-- | clang/lib/Frontend/CompilerInstance.cpp | 9 | ||||
-rw-r--r-- | clang/lib/Frontend/CompilerInvocation.cpp | 3 | ||||
-rw-r--r-- | clang/test/Driver/modules.m | 5 | ||||
-rw-r--r-- | clang/test/Modules/validate-system-headers.m | 25 |
7 files changed, 49 insertions, 4 deletions
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index b3dd5c3b906..fd8b823d0b3 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -591,6 +591,9 @@ def fmodules_validate_once_per_build_session : Flag<["-"], "fmodules-validate-on Group<i_Group>, Flags<[CC1Option]>, HelpText<"Don't verify input files for the modules if the module has been " "successfully validate or loaded during this build session">; +def fmodules_validate_system_headers : Flag<["-"], "fmodules-validate-system-headers">, + Group<i_Group>, Flags<[CC1Option]>, + HelpText<"Validate the system headers that a module depends on when loading the module">; def fmodules : Flag <["-"], "fmodules">, Group<f_Group>, Flags<[DriverOption, CC1Option]>, HelpText<"Enable the 'modules' language feature">; diff --git a/clang/include/clang/Lex/HeaderSearchOptions.h b/clang/include/clang/Lex/HeaderSearchOptions.h index 53b4bdc4c9f..06024b2e90f 100644 --- a/clang/include/clang/Lex/HeaderSearchOptions.h +++ b/clang/include/clang/Lex/HeaderSearchOptions.h @@ -155,6 +155,9 @@ public: /// \c BuildSessionTimestamp). unsigned ModulesValidateOncePerBuildSession : 1; + /// \brief Whether to validate system input files when a module is loaded. + unsigned ModulesValidateSystemHeaders : 1; + public: HeaderSearchOptions(StringRef _Sysroot = "/") : Sysroot(_Sysroot), DisableModuleHash(0), ModuleMaps(0), @@ -164,7 +167,8 @@ public: UseBuiltinIncludes(true), UseStandardSystemIncludes(true), UseStandardCXXIncludes(true), UseLibcxx(false), Verbose(false), - ModulesValidateOncePerBuildSession(false) {} + ModulesValidateOncePerBuildSession(false), + ModulesValidateSystemHeaders(false) {} /// AddPath - Add the \p Path path to the specified \p Group list. void AddPath(StringRef Path, frontend::IncludeDirGroup Group, diff --git a/clang/lib/Driver/Tools.cpp b/clang/lib/Driver/Tools.cpp index 537390a7da3..cc944885ad4 100644 --- a/clang/lib/Driver/Tools.cpp +++ b/clang/lib/Driver/Tools.cpp @@ -3390,6 +3390,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, options::OPT_fmodules_validate_once_per_build_session); } + Args.AddLastArg(CmdArgs, options::OPT_fmodules_validate_system_headers); + // -faccess-control is default. if (Args.hasFlag(options::OPT_fno_access_control, options::OPT_faccess_control, diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index 11b5ba9f549..ce47674edbc 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -334,13 +334,15 @@ CompilerInstance::createPCHExternalASTSource(StringRef Path, void *DeserializationListener, bool Preamble, bool UseGlobalModuleIndex) { + HeaderSearchOptions &HSOpts = PP.getHeaderSearchInfo().getHeaderSearchOpts(); + std::unique_ptr<ASTReader> Reader; Reader.reset(new ASTReader(PP, Context, Sysroot.empty() ? "" : Sysroot.c_str(), DisablePCHValidation, AllowPCHWithCompilerErrors, /*AllowConfigurationMismatch*/false, - /*ValidateSystemInputs*/false, + HSOpts.ModulesValidateSystemHeaders, UseGlobalModuleIndex)); Reader->setDeserializationListener( @@ -1141,14 +1143,15 @@ CompilerInstance::loadModule(SourceLocation ImportLoc, pruneModuleCache(getHeaderSearchOpts()); } - std::string Sysroot = getHeaderSearchOpts().Sysroot; + HeaderSearchOptions &HSOpts = getHeaderSearchOpts(); + std::string Sysroot = HSOpts.Sysroot; const PreprocessorOptions &PPOpts = getPreprocessorOpts(); ModuleManager = new ASTReader(getPreprocessor(), *Context, Sysroot.empty() ? "" : Sysroot.c_str(), PPOpts.DisablePCHValidation, /*AllowASTWithCompilerErrors=*/false, /*AllowConfigurationMismatch=*/false, - /*ValidateSystemInputs=*/false, + HSOpts.ModulesValidateSystemHeaders, getFrontendOpts().UseGlobalModuleIndex); if (hasASTConsumer()) { ModuleManager->setDeserializationListener( diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index 20e59c2726c..f368837a5f0 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -930,6 +930,9 @@ static void ParseHeaderSearchArgs(HeaderSearchOptions &Opts, ArgList &Args) { Args.hasArg(OPT_fmodules_validate_once_per_build_session); Opts.BuildSessionTimestamp = getLastArgUInt64Value(Args, OPT_fbuild_session_timestamp, 0); + Opts.ModulesValidateSystemHeaders = + Args.hasArg(OPT_fmodules_validate_system_headers); + for (arg_iterator it = Args.filtered_begin(OPT_fmodules_ignore_macro), ie = Args.filtered_end(); it != ie; ++it) { diff --git a/clang/test/Driver/modules.m b/clang/test/Driver/modules.m index 7b14f21443f..d8e20e4148e 100644 --- a/clang/test/Driver/modules.m +++ b/clang/test/Driver/modules.m @@ -14,3 +14,8 @@ // RUN: %clang -fmodules-validate-once-per-build-session -### %s 2>&1 | FileCheck -check-prefix=MODULES_VALIDATE_ONCE_ERR %s // MODULES_VALIDATE_ONCE_ERR: option '-fmodules-validate-once-per-build-session' requires '-fbuild-session-timestamp=<seconds since Epoch>' +// RUN: %clang -### %s 2>&1 | FileCheck -check-prefix=MODULES_VALIDATE_SYSTEM_HEADERS_DEFAULT %s +// MODULES_VALIDATE_SYSTEM_HEADERS_DEFAULT-NOT: -fmodules-validate-system-headers + +// RUN: %clang -fmodules-validate-system-headers -### %s 2>&1 | FileCheck -check-prefix=MODULES_VALIDATE_SYSTEM_HEADERS %s +// MODULES_VALIDATE_SYSTEM_HEADERS: -fmodules-validate-system-headers diff --git a/clang/test/Modules/validate-system-headers.m b/clang/test/Modules/validate-system-headers.m new file mode 100644 index 00000000000..9fb2bd2a637 --- /dev/null +++ b/clang/test/Modules/validate-system-headers.m @@ -0,0 +1,25 @@ +// RUN: rm -rf %t/ModuleCache +// RUN: mkdir -p %t/Inputs/usr/include +// RUN: touch %t/Inputs/usr/include/foo.h +// RUN: echo 'module Foo [system] { header "foo.h" }' > %t/Inputs/usr/include/module.map + +//// +// Build a module using a system header +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -isysroot %t/Inputs -fmodules -fmodules-cache-path=%t/ModuleCache -fdisable-module-hash -x objective-c-header -fsyntax-only %s +// RUN: cp %t/ModuleCache/Foo.pcm %t/Foo.pcm.saved + +//// +// Modify the system header, and confirm that we don't notice without -fmodules-validate-system-headers. +// The pcm file in the cache should fail to validate. +// RUN: echo ' ' >> %t/Inputs/usr/include/foo.h +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -isysroot %t/Inputs -fmodules -fmodules-cache-path=%t/ModuleCache -fdisable-module-hash -x objective-c-header -fsyntax-only %s +// RUN: diff %t/ModuleCache/Foo.pcm %t/Foo.pcm.saved + +//// +// Now make sure we rebuild the module when -fmodules-validate-system-headers is set. +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -isysroot %t/Inputs -fmodules -fmodules-validate-system-headers -fmodules-cache-path=%t/ModuleCache -fdisable-module-hash -x objective-c-header -fsyntax-only %s +// RUN: not diff %t/ModuleCache/Foo.pcm %t/Foo.pcm.saved + +// REQUIRES: shell + +@import Foo; |