diff options
Diffstat (limited to 'clang/lib/Serialization/ASTReader.cpp')
-rw-r--r-- | clang/lib/Serialization/ASTReader.cpp | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp index f8e4384c630..bb39a436abe 100644 --- a/clang/lib/Serialization/ASTReader.cpp +++ b/clang/lib/Serialization/ASTReader.cpp @@ -496,12 +496,16 @@ collectMacroDefinitions(const PreprocessorOptions &PPOpts, /// against the preprocessor options in an existing preprocessor. /// /// \param Diags If non-null, produce diagnostics for any mismatches incurred. +/// \param Validate If true, validate preprocessor options. If false, allow +/// macros defined by \p ExistingPPOpts to override those defined by +/// \p PPOpts in SuggestedPredefines. static bool checkPreprocessorOptions(const PreprocessorOptions &PPOpts, const PreprocessorOptions &ExistingPPOpts, DiagnosticsEngine *Diags, FileManager &FileMgr, std::string &SuggestedPredefines, - const LangOptions &LangOpts) { + const LangOptions &LangOpts, + bool Validate = true) { // Check macro definitions. MacroDefinitionsMap ASTFileMacros; collectMacroDefinitions(PPOpts, ASTFileMacros); @@ -517,7 +521,7 @@ static bool checkPreprocessorOptions(const PreprocessorOptions &PPOpts, // Check whether we know anything about this macro name or not. llvm::StringMap<std::pair<StringRef, bool /*IsUndef*/> >::iterator Known = ASTFileMacros.find(MacroName); - if (Known == ASTFileMacros.end()) { + if (!Validate || Known == ASTFileMacros.end()) { // FIXME: Check whether this identifier was referenced anywhere in the // AST file. If so, we should reject the AST file. Unfortunately, this // information isn't in the control block. What shall we do about it? @@ -560,7 +564,7 @@ static bool checkPreprocessorOptions(const PreprocessorOptions &PPOpts, } // Check whether we're using predefines. - if (PPOpts.UsePredefines != ExistingPPOpts.UsePredefines) { + if (PPOpts.UsePredefines != ExistingPPOpts.UsePredefines && Validate) { if (Diags) { Diags->Report(diag::err_pch_undef) << ExistingPPOpts.UsePredefines; } @@ -569,7 +573,7 @@ static bool checkPreprocessorOptions(const PreprocessorOptions &PPOpts, // Detailed record is important since it is used for the module cache hash. if (LangOpts.Modules && - PPOpts.DetailedRecord != ExistingPPOpts.DetailedRecord) { + PPOpts.DetailedRecord != ExistingPPOpts.DetailedRecord && Validate) { if (Diags) { Diags->Report(diag::err_pch_pp_detailed_record) << PPOpts.DetailedRecord; } @@ -618,6 +622,19 @@ bool PCHValidator::ReadPreprocessorOptions(const PreprocessorOptions &PPOpts, PP.getLangOpts()); } +bool SimpleASTReaderListener::ReadPreprocessorOptions( + const PreprocessorOptions &PPOpts, + bool Complain, + std::string &SuggestedPredefines) { + return checkPreprocessorOptions(PPOpts, + PP.getPreprocessorOpts(), + nullptr, + PP.getFileManager(), + SuggestedPredefines, + PP.getLangOpts(), + false); +} + /// Check the header search options deserialized from the control block /// against the header search options in an existing preprocessor. /// @@ -8710,7 +8727,10 @@ ASTReader::ASTReader( bool AllowConfigurationMismatch, bool ValidateSystemInputs, bool UseGlobalIndex, std::unique_ptr<llvm::Timer> ReadTimer) - : Listener(new PCHValidator(PP, *this)), DeserializationListener(nullptr), + : Listener(DisableValidation ? + cast<ASTReaderListener>(new SimpleASTReaderListener(PP)) : + cast<ASTReaderListener>(new PCHValidator(PP, *this))), + DeserializationListener(nullptr), OwnsDeserializationListener(false), SourceMgr(PP.getSourceManager()), FileMgr(PP.getFileManager()), PCHContainerRdr(PCHContainerRdr), Diags(PP.getDiagnostics()), SemaObj(nullptr), PP(PP), Context(Context), |