@@ -208,11 +208,12 @@ bool ChainedASTReaderListener::ReadHeaderSearchOptions(
208
208
}
209
209
210
210
bool ChainedASTReaderListener::ReadPreprocessorOptions (
211
- const PreprocessorOptions &PPOpts, bool Complain,
211
+ const PreprocessorOptions &PPOpts, bool ReadMacros, bool Complain,
212
212
std::string &SuggestedPredefines) {
213
- return First->ReadPreprocessorOptions (PPOpts, Complain,
213
+ return First->ReadPreprocessorOptions (PPOpts, ReadMacros, Complain,
214
214
SuggestedPredefines) ||
215
- Second->ReadPreprocessorOptions (PPOpts, Complain, SuggestedPredefines);
215
+ Second->ReadPreprocessorOptions (PPOpts, ReadMacros, Complain,
216
+ SuggestedPredefines);
216
217
}
217
218
218
219
void ChainedASTReaderListener::ReadCounter (const serialization::ModuleFile &M,
@@ -668,68 +669,70 @@ enum OptionValidation {
668
669
// / are no differences in the options between the two.
669
670
static bool checkPreprocessorOptions (
670
671
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,
674
675
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) {
683
686
// Dig out the macro definition in the existing preprocessor options.
684
687
StringRef MacroName = ExistingMacroNames[I];
685
688
std::pair<StringRef, bool > Existing = ExistingMacros[MacroName];
686
689
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 ) {
694
723
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 ;
696
726
}
697
727
return true ;
698
728
}
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
- }
716
729
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 ;
723
735
}
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
- }
733
736
734
737
// The macro bodies differ; complain.
735
738
if (Diags) {
@@ -745,7 +748,7 @@ static bool checkPreprocessorOptions(
745
748
if (Diags) {
746
749
Diags->Report (diag::err_pch_macro_def_undef) << MacroName << false ;
747
750
}
748
- return true ;
751
+ return true ;}
749
752
}
750
753
}
751
754
@@ -807,24 +810,22 @@ static bool checkPreprocessorOptions(
807
810
}
808
811
809
812
bool PCHValidator::ReadPreprocessorOptions (const PreprocessorOptions &PPOpts,
810
- bool Complain,
813
+ bool ReadMacros, bool Complain,
811
814
std::string &SuggestedPredefines) {
812
815
const PreprocessorOptions &ExistingPPOpts = PP.getPreprocessorOpts ();
813
816
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 ());
819
820
}
820
821
821
822
bool 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);
828
829
}
829
830
830
831
// / Check the header search options deserialized from the control block
@@ -5234,10 +5235,10 @@ namespace {
5234
5235
}
5235
5236
5236
5237
bool ReadPreprocessorOptions (const PreprocessorOptions &PPOpts,
5237
- bool Complain,
5238
+ bool ReadMacros, bool Complain,
5238
5239
std::string &SuggestedPredefines) override {
5239
5240
return checkPreprocessorOptions (
5240
- PPOpts, ExistingPPOpts, /* Diags=*/ nullptr , FileMgr,
5241
+ PPOpts, ExistingPPOpts, ReadMacros, /* Diags=*/ nullptr , FileMgr,
5241
5242
SuggestedPredefines, ExistingLangOpts,
5242
5243
StrictOptionMatches ? OptionValidateStrictMatches
5243
5244
: OptionValidateContradictions);
@@ -6018,10 +6019,13 @@ bool ASTReader::ParsePreprocessorOptions(const RecordData &Record,
6018
6019
unsigned Idx = 0 ;
6019
6020
6020
6021
// 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
+ }
6025
6029
}
6026
6030
6027
6031
// Includes
@@ -6040,7 +6044,7 @@ bool ASTReader::ParsePreprocessorOptions(const RecordData &Record,
6040
6044
PPOpts.ObjCXXARCStandardLibrary =
6041
6045
static_cast <ObjCXXARCStandardLibraryKind>(Record[Idx++]);
6042
6046
SuggestedPredefines.clear ();
6043
- return Listener.ReadPreprocessorOptions (PPOpts, Complain,
6047
+ return Listener.ReadPreprocessorOptions (PPOpts, ReadMacros, Complain,
6044
6048
SuggestedPredefines);
6045
6049
}
6046
6050
0 commit comments