forked from OSchip/llvm-project
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
This commit is contained in:
parent
e8d69b7fc9
commit
dcf73861a5
|
@ -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">;
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
Loading…
Reference in New Issue