r203630 - Add an option -fmodules-validate-system-headers
Ben Langmuir
blangmuir at apple.com
Tue Mar 11 17:06:17 PDT 2014
Author: benlangmuir
Date: Tue Mar 11 19:06:17 2014
New Revision: 203630
URL: http://llvm.org/viewvc/llvm-project?rev=203630&view=rev
Log:
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.
Added:
cfe/trunk/test/Modules/validate-system-headers.m
Modified:
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/include/clang/Lex/HeaderSearchOptions.h
cfe/trunk/lib/Driver/Tools.cpp
cfe/trunk/lib/Frontend/CompilerInstance.cpp
cfe/trunk/lib/Frontend/CompilerInvocation.cpp
cfe/trunk/test/Driver/modules.m
Modified: cfe/trunk/include/clang/Driver/Options.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=203630&r1=203629&r2=203630&view=diff
==============================================================================
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Tue Mar 11 19:06:17 2014
@@ -591,6 +591,9 @@ def fmodules_validate_once_per_build_ses
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">;
Modified: cfe/trunk/include/clang/Lex/HeaderSearchOptions.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/HeaderSearchOptions.h?rev=203630&r1=203629&r2=203630&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/HeaderSearchOptions.h (original)
+++ cfe/trunk/include/clang/Lex/HeaderSearchOptions.h Tue Mar 11 19:06:17 2014
@@ -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,
Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=203630&r1=203629&r2=203630&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Tue Mar 11 19:06:17 2014
@@ -3390,6 +3390,8 @@ void Clang::ConstructJob(Compilation &C,
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,
Modified: cfe/trunk/lib/Frontend/CompilerInstance.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInstance.cpp?rev=203630&r1=203629&r2=203630&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/CompilerInstance.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInstance.cpp Tue Mar 11 19:06:17 2014
@@ -334,13 +334,15 @@ CompilerInstance::createPCHExternalASTSo
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(SourceLocat
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(
Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=203630&r1=203629&r2=203630&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Tue Mar 11 19:06:17 2014
@@ -930,6 +930,9 @@ static void ParseHeaderSearchArgs(Header
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) {
Modified: cfe/trunk/test/Driver/modules.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/modules.m?rev=203630&r1=203629&r2=203630&view=diff
==============================================================================
--- cfe/trunk/test/Driver/modules.m (original)
+++ cfe/trunk/test/Driver/modules.m Tue Mar 11 19:06:17 2014
@@ -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
Added: cfe/trunk/test/Modules/validate-system-headers.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/validate-system-headers.m?rev=203630&view=auto
==============================================================================
--- cfe/trunk/test/Modules/validate-system-headers.m (added)
+++ cfe/trunk/test/Modules/validate-system-headers.m Tue Mar 11 19:06:17 2014
@@ -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
+
+ at import Foo;
More information about the cfe-commits
mailing list