diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2014-10-31 02:28:58 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2014-10-31 02:28:58 +0000 |
commit | 78c81e530e2b92d790fedb3468ab292abfb14b1a (patch) | |
tree | 9f9141ec490de7c9a0983e9686dc7bf28cd41c66 /lib/Serialization | |
parent | 9dc7a86e6214db00d7d00aa8bb67fa5fcc2d6e0a (diff) |
[modules] When a .pcm file is explicitly built separately from the translation
unit, allow the -O settings of the two compilations to differ.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@220943 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Serialization')
-rw-r--r-- | lib/Serialization/ASTReader.cpp | 65 |
1 files changed, 47 insertions, 18 deletions
diff --git a/lib/Serialization/ASTReader.cpp b/lib/Serialization/ASTReader.cpp index 8fc68165d6..37a5ac1b2a 100644 --- a/lib/Serialization/ASTReader.cpp +++ b/lib/Serialization/ASTReader.cpp @@ -80,10 +80,14 @@ void ChainedASTReaderListener::ReadModuleMapFile(StringRef ModuleMapPath) { First->ReadModuleMapFile(ModuleMapPath); Second->ReadModuleMapFile(ModuleMapPath); } -bool ChainedASTReaderListener::ReadLanguageOptions(const LangOptions &LangOpts, - bool Complain) { - return First->ReadLanguageOptions(LangOpts, Complain) || - Second->ReadLanguageOptions(LangOpts, Complain); +bool +ChainedASTReaderListener::ReadLanguageOptions(const LangOptions &LangOpts, + bool Complain, + bool AllowCompatibleDifferences) { + return First->ReadLanguageOptions(LangOpts, Complain, + AllowCompatibleDifferences) || + Second->ReadLanguageOptions(LangOpts, Complain, + AllowCompatibleDifferences); } bool ChainedASTReaderListener::ReadTargetOptions(const TargetOptions &TargetOpts, @@ -155,11 +159,14 @@ ASTReaderListener::~ASTReaderListener() {} /// language options. /// /// \param Diags If non-NULL, diagnostics will be emitted via this engine. +/// \param AllowCompatibleDifferences If true, differences between compatible +/// language options will be permitted. /// /// \returns true if the languagae options mis-match, false otherwise. static bool checkLanguageOptions(const LangOptions &LangOpts, const LangOptions &ExistingLangOpts, - DiagnosticsEngine *Diags) { + DiagnosticsEngine *Diags, + bool AllowCompatibleDifferences = true) { #define LANGOPT(Name, Bits, Default, Description) \ if (ExistingLangOpts.Name != LangOpts.Name) { \ if (Diags) \ @@ -184,6 +191,14 @@ static bool checkLanguageOptions(const LangOptions &LangOpts, return true; \ } +#define COMPATIBLE_LANGOPT(Name, Bits, Default, Description) \ + if (!AllowCompatibleDifferences) \ + LANGOPT(Name, Bits, Default, Description) + +#define COMPATIBLE_ENUM_LANGOPT(Name, Bits, Default, Description) \ + if (!AllowCompatibleDifferences) \ + ENUM_LANGOPT(Name, Bits, Default, Description) + #define BENIGN_LANGOPT(Name, Bits, Default, Description) #define BENIGN_ENUM_LANGOPT(Name, Type, Bits, Default, Description) #include "clang/Basic/LangOptions.def" @@ -278,10 +293,12 @@ static bool checkTargetOptions(const TargetOptions &TargetOpts, bool PCHValidator::ReadLanguageOptions(const LangOptions &LangOpts, - bool Complain) { + bool Complain, + bool AllowCompatibleDifferences) { const LangOptions &ExistingLangOpts = PP.getLangOpts(); return checkLanguageOptions(LangOpts, ExistingLangOpts, - Complain? &Reader.Diags : nullptr); + Complain ? &Reader.Diags : nullptr, + AllowCompatibleDifferences); } bool PCHValidator::ReadTargetOptions(const TargetOptions &TargetOpts, @@ -2261,6 +2278,12 @@ ASTReader::ReadControlBlock(ModuleFile &F, return Failure; } + // Should we allow the configuration of the module file to differ from the + // configuration of the current translation unit in a compatible way? + // + // FIXME: Allow this for files explicitly specified with -include-pch too. + bool AllowCompatibleConfigurationMismatch = F.Kind == MK_ExplicitModule; + // Read all of the records and blocks in the control block. RecordData Record; unsigned NumInputs = 0; @@ -2415,8 +2438,10 @@ ASTReader::ReadControlBlock(ModuleFile &F, case LANGUAGE_OPTIONS: { bool Complain = (ClientLoadCapabilities & ARR_ConfigurationMismatch) == 0; + // FIXME: The &F == *ModuleMgr.begin() check is wrong for modules. if (Listener && &F == *ModuleMgr.begin() && - ParseLanguageOptions(Record, Complain, *Listener) && + ParseLanguageOptions(Record, Complain, *Listener, + AllowCompatibleConfigurationMismatch) && !DisableValidation && !AllowConfigurationMismatch) return ConfigurationMismatch; break; @@ -2434,7 +2459,7 @@ ASTReader::ReadControlBlock(ModuleFile &F, case DIAGNOSTIC_OPTIONS: { bool Complain = (ClientLoadCapabilities & ARR_OutOfDate)==0; if (Listener && &F == *ModuleMgr.begin() && - F.Kind != MK_ExplicitModule && + !AllowCompatibleConfigurationMismatch && ParseDiagnosticOptions(Record, Complain, *Listener) && !DisableValidation) return OutOfDate; @@ -2444,7 +2469,7 @@ ASTReader::ReadControlBlock(ModuleFile &F, case FILE_SYSTEM_OPTIONS: { bool Complain = (ClientLoadCapabilities & ARR_ConfigurationMismatch)==0; if (Listener && &F == *ModuleMgr.begin() && - F.Kind != MK_ExplicitModule && + !AllowCompatibleConfigurationMismatch && ParseFileSystemOptions(Record, Complain, *Listener) && !DisableValidation && !AllowConfigurationMismatch) return ConfigurationMismatch; @@ -2454,7 +2479,7 @@ ASTReader::ReadControlBlock(ModuleFile &F, case HEADER_SEARCH_OPTIONS: { bool Complain = (ClientLoadCapabilities & ARR_ConfigurationMismatch)==0; if (Listener && &F == *ModuleMgr.begin() && - F.Kind != MK_ExplicitModule && + !AllowCompatibleConfigurationMismatch && ParseHeaderSearchOptions(Record, Complain, *Listener) && !DisableValidation && !AllowConfigurationMismatch) return ConfigurationMismatch; @@ -2464,7 +2489,7 @@ ASTReader::ReadControlBlock(ModuleFile &F, case PREPROCESSOR_OPTIONS: { bool Complain = (ClientLoadCapabilities & ARR_ConfigurationMismatch)==0; if (Listener && &F == *ModuleMgr.begin() && - F.Kind != MK_ExplicitModule && + !AllowCompatibleConfigurationMismatch && ParsePreprocessorOptions(Record, Complain, *Listener, SuggestedPredefines) && !DisableValidation && !AllowConfigurationMismatch) @@ -4156,9 +4181,10 @@ namespace { { } - bool ReadLanguageOptions(const LangOptions &LangOpts, - bool Complain) override { - return checkLanguageOptions(ExistingLangOpts, LangOpts, nullptr); + bool ReadLanguageOptions(const LangOptions &LangOpts, bool Complain, + bool AllowCompatibleDifferences) override { + return checkLanguageOptions(ExistingLangOpts, LangOpts, nullptr, + AllowCompatibleDifferences); } bool ReadTargetOptions(const TargetOptions &TargetOpts, bool Complain) override { @@ -4256,7 +4282,8 @@ bool ASTReader::readASTFileControlBlock(StringRef Filename, break; } case LANGUAGE_OPTIONS: - if (ParseLanguageOptions(Record, false, Listener)) + if (ParseLanguageOptions(Record, false, Listener, + /*AllowCompatibleConfigurationMismatch*/false)) return true; break; @@ -4612,7 +4639,8 @@ ASTReader::ReadSubmoduleBlock(ModuleFile &F, unsigned ClientLoadCapabilities) { /// \returns true if the listener deems the file unacceptable, false otherwise. bool ASTReader::ParseLanguageOptions(const RecordData &Record, bool Complain, - ASTReaderListener &Listener) { + ASTReaderListener &Listener, + bool AllowCompatibleDifferences) { LangOptions LangOpts; unsigned Idx = 0; #define LANGOPT(Name, Bits, Default, Description) \ @@ -4640,7 +4668,8 @@ bool ASTReader::ParseLanguageOptions(const RecordData &Record, } LangOpts.CommentOpts.ParseAllComments = Record[Idx++]; - return Listener.ReadLanguageOptions(LangOpts, Complain); + return Listener.ReadLanguageOptions(LangOpts, Complain, + AllowCompatibleDifferences); } bool ASTReader::ParseTargetOptions(const RecordData &Record, |