@@ -208,11 +208,12 @@ bool ChainedASTReaderListener::ReadHeaderSearchOptions(
208208}
209209
210210bool ChainedASTReaderListener::ReadPreprocessorOptions (
211- const PreprocessorOptions &PPOpts, bool Complain,
211+ const PreprocessorOptions &PPOpts, bool ReadMacros, bool Complain,
212212 std::string &SuggestedPredefines) {
213- return First->ReadPreprocessorOptions (PPOpts, Complain,
213+ return First->ReadPreprocessorOptions (PPOpts, ReadMacros, Complain,
214214 SuggestedPredefines) ||
215- Second->ReadPreprocessorOptions (PPOpts, Complain, SuggestedPredefines);
215+ Second->ReadPreprocessorOptions (PPOpts, ReadMacros, Complain,
216+ SuggestedPredefines);
216217}
217218
218219void ChainedASTReaderListener::ReadCounter (const serialization::ModuleFile &M,
@@ -668,68 +669,70 @@ enum OptionValidation {
668669// / are no differences in the options between the two.
669670static bool checkPreprocessorOptions (
670671 const PreprocessorOptions &PPOpts,
671- const PreprocessorOptions &ExistingPPOpts, DiagnosticsEngine *Diags ,
672- FileManager &FileMgr, std::string &SuggestedPredefines ,
673- const LangOptions &LangOpts,
672+ const PreprocessorOptions &ExistingPPOpts, bool ReadMacros ,
673+ DiagnosticsEngine *Diags, FileManager &FileMgr ,
674+ std::string &SuggestedPredefines, const LangOptions &LangOpts,
674675 OptionValidation Validation = OptionValidateContradictions) {
675- // Check macro definitions.
676- MacroDefinitionsMap ASTFileMacros;
677- collectMacroDefinitions (PPOpts, ASTFileMacros);
678- MacroDefinitionsMap ExistingMacros;
679- SmallVector<StringRef, 4 > ExistingMacroNames;
680- collectMacroDefinitions (ExistingPPOpts, ExistingMacros, &ExistingMacroNames);
681-
682- for (unsigned I = 0 , N = ExistingMacroNames.size (); I != N; ++I) {
676+ if (ReadMacros) {
677+ // Check macro definitions.
678+ MacroDefinitionsMap ASTFileMacros;
679+ collectMacroDefinitions (PPOpts, ASTFileMacros);
680+ MacroDefinitionsMap ExistingMacros;
681+ SmallVector<StringRef, 4 > ExistingMacroNames;
682+ collectMacroDefinitions (ExistingPPOpts, ExistingMacros,
683+ &ExistingMacroNames);
684+
685+ for (unsigned I = 0 , N = ExistingMacroNames.size (); I != N; ++I) {
683686 // Dig out the macro definition in the existing preprocessor options.
684687 StringRef MacroName = ExistingMacroNames[I];
685688 std::pair<StringRef, bool > Existing = ExistingMacros[MacroName];
686689
687- // Check whether we know anything about this macro name or not.
688- llvm::StringMap<std::pair<StringRef, bool /* IsUndef*/ >>::iterator Known =
689- ASTFileMacros.find (MacroName);
690- if (Validation == OptionValidateNone || Known == ASTFileMacros.end ()) {
691- if (Validation == OptionValidateStrictMatches) {
692- // If strict matches are requested, don't tolerate any extra defines on
693- // the command line that are missing in the AST file.
690+ // Check whether we know anything about this macro name or not.
691+ llvm::StringMap<std::pair<StringRef, bool /* IsUndef*/ >>::iterator Known =
692+ ASTFileMacros.find (MacroName);
693+ if (Validation == OptionValidateNone || Known == ASTFileMacros.end ()) {
694+ if (Validation == OptionValidateStrictMatches) {
695+ // If strict matches are requested, don't tolerate any extra defines
696+ // on the command line that are missing in the AST file.
697+ if (Diags) {
698+ Diags->Report (diag::err_pch_macro_def_undef) << MacroName << true ;
699+ }
700+ return true ;
701+ }
702+ // FIXME: Check whether this identifier was referenced anywhere in the
703+ // AST file. If so, we should reject the AST file. Unfortunately, this
704+ // information isn't in the control block. What shall we do about it?
705+
706+ if (Existing.second ) {
707+ SuggestedPredefines += " #undef " ;
708+ SuggestedPredefines += MacroName.str ();
709+ SuggestedPredefines += ' \n ' ;
710+ } else {
711+ SuggestedPredefines += " #define " ;
712+ SuggestedPredefines += MacroName.str ();
713+ SuggestedPredefines += ' ' ;
714+ SuggestedPredefines += Existing.first .str ();
715+ SuggestedPredefines += ' \n ' ;
716+ }
717+ continue ;
718+ }
719+
720+ // If the macro was defined in one but undef'd in the other, we have a
721+ // conflict.
722+ if (Existing.second != Known->second .second ) {
694723 if (Diags) {
695- Diags->Report (diag::err_pch_macro_def_undef) << MacroName << true ;
724+ Diags->Report (diag::err_pch_macro_def_undef)
725+ << MacroName << Known->second .second ;
696726 }
697727 return true ;
698728 }
699- // FIXME: Check whether this identifier was referenced anywhere in the
700- // AST file. If so, we should reject the AST file. Unfortunately, this
701- // information isn't in the control block. What shall we do about it?
702-
703- if (Existing.second ) {
704- SuggestedPredefines += " #undef " ;
705- SuggestedPredefines += MacroName.str ();
706- SuggestedPredefines += ' \n ' ;
707- } else {
708- SuggestedPredefines += " #define " ;
709- SuggestedPredefines += MacroName.str ();
710- SuggestedPredefines += ' ' ;
711- SuggestedPredefines += Existing.first .str ();
712- SuggestedPredefines += ' \n ' ;
713- }
714- continue ;
715- }
716729
717- // If the macro was defined in one but undef'd in the other, we have a
718- // conflict.
719- if (Existing.second != Known->second .second ) {
720- if (Diags) {
721- Diags->Report (diag::err_pch_macro_def_undef)
722- << MacroName << Known->second .second ;
730+ // If the macro was #undef'd in both, or if the macro bodies are
731+ // identical, it's fine.
732+ if (Existing.second || Existing.first == Known->second .first ) {
733+ ASTFileMacros.erase (Known);
734+ continue ;
723735 }
724- return true ;
725- }
726-
727- // If the macro was #undef'd in both, or if the macro bodies are identical,
728- // it's fine.
729- if (Existing.second || Existing.first == Known->second .first ) {
730- ASTFileMacros.erase (Known);
731- continue ;
732- }
733736
734737 // The macro bodies differ; complain.
735738 if (Diags) {
@@ -745,7 +748,7 @@ static bool checkPreprocessorOptions(
745748 if (Diags) {
746749 Diags->Report (diag::err_pch_macro_def_undef) << MacroName << false ;
747750 }
748- return true ;
751+ return true ;}
749752 }
750753 }
751754
@@ -807,24 +810,22 @@ static bool checkPreprocessorOptions(
807810}
808811
809812bool PCHValidator::ReadPreprocessorOptions (const PreprocessorOptions &PPOpts,
810- bool Complain,
813+ bool ReadMacros, bool Complain,
811814 std::string &SuggestedPredefines) {
812815 const PreprocessorOptions &ExistingPPOpts = PP.getPreprocessorOpts ();
813816
814- return checkPreprocessorOptions (PPOpts, ExistingPPOpts,
815- Complain? &Reader.Diags : nullptr ,
816- PP.getFileManager (),
817- SuggestedPredefines,
818- PP.getLangOpts ());
817+ return checkPreprocessorOptions (
818+ PPOpts, ExistingPPOpts, ReadMacros, Complain ? &Reader.Diags : nullptr ,
819+ PP.getFileManager (), SuggestedPredefines, PP.getLangOpts ());
819820}
820821
821822bool SimpleASTReaderListener::ReadPreprocessorOptions (
822- const PreprocessorOptions &PPOpts,
823- bool Complain,
824- std::string &SuggestedPredefines) {
825- return checkPreprocessorOptions (PPOpts , PP.getPreprocessorOpts (), nullptr ,
826- PP.getFileManager (), SuggestedPredefines ,
827- PP. getLangOpts (), OptionValidateNone);
823+ const PreprocessorOptions &PPOpts, bool ReadMacros, bool Complain ,
824+ std::string &SuggestedPredefines) {
825+ return checkPreprocessorOptions (PPOpts, PP. getPreprocessorOpts (), ReadMacros,
826+ nullptr , PP.getFileManager () ,
827+ SuggestedPredefines, PP.getLangOpts () ,
828+ OptionValidateNone);
828829}
829830
830831// / Check the header search options deserialized from the control block
@@ -5234,10 +5235,10 @@ namespace {
52345235 }
52355236
52365237 bool ReadPreprocessorOptions (const PreprocessorOptions &PPOpts,
5237- bool Complain,
5238+ bool ReadMacros, bool Complain,
52385239 std::string &SuggestedPredefines) override {
52395240 return checkPreprocessorOptions (
5240- PPOpts, ExistingPPOpts, /* Diags=*/ nullptr , FileMgr,
5241+ PPOpts, ExistingPPOpts, ReadMacros, /* Diags=*/ nullptr , FileMgr,
52415242 SuggestedPredefines, ExistingLangOpts,
52425243 StrictOptionMatches ? OptionValidateStrictMatches
52435244 : OptionValidateContradictions);
@@ -6018,10 +6019,13 @@ bool ASTReader::ParsePreprocessorOptions(const RecordData &Record,
60186019 unsigned Idx = 0 ;
60196020
60206021 // Macro definitions/undefs
6021- for (unsigned N = Record[Idx++]; N; --N) {
6022- std::string Macro = ReadString (Record, Idx);
6023- bool IsUndef = Record[Idx++];
6024- PPOpts.Macros .push_back (std::make_pair (Macro, IsUndef));
6022+ bool ReadMacros = Record[Idx++];
6023+ if (ReadMacros) {
6024+ for (unsigned N = Record[Idx++]; N; --N) {
6025+ std::string Macro = ReadString (Record, Idx);
6026+ bool IsUndef = Record[Idx++];
6027+ PPOpts.Macros .push_back (std::make_pair (Macro, IsUndef));
6028+ }
60256029 }
60266030
60276031 // Includes
@@ -6040,7 +6044,7 @@ bool ASTReader::ParsePreprocessorOptions(const RecordData &Record,
60406044 PPOpts.ObjCXXARCStandardLibrary =
60416045 static_cast <ObjCXXARCStandardLibraryKind>(Record[Idx++]);
60426046 SuggestedPredefines.clear ();
6043- return Listener.ReadPreprocessorOptions (PPOpts, Complain,
6047+ return Listener.ReadPreprocessorOptions (PPOpts, ReadMacros, Complain,
60446048 SuggestedPredefines);
60456049}
60466050
0 commit comments