@@ -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,
@@ -658,92 +659,95 @@ enum OptionValidation {
658
659
// / are no differences in the options between the two.
659
660
static bool checkPreprocessorOptions (
660
661
const PreprocessorOptions &PPOpts,
661
- const PreprocessorOptions &ExistingPPOpts, DiagnosticsEngine *Diags ,
662
- FileManager &FileMgr, std::string &SuggestedPredefines ,
663
- const LangOptions &LangOpts,
662
+ const PreprocessorOptions &ExistingPPOpts, bool ReadMacros ,
663
+ DiagnosticsEngine *Diags, FileManager &FileMgr ,
664
+ std::string &SuggestedPredefines, const LangOptions &LangOpts,
664
665
OptionValidation Validation = OptionValidateContradictions) {
665
- // Check macro definitions.
666
- MacroDefinitionsMap ASTFileMacros;
667
- collectMacroDefinitions (PPOpts, ASTFileMacros);
668
- MacroDefinitionsMap ExistingMacros;
669
- SmallVector<StringRef, 4 > ExistingMacroNames;
670
- collectMacroDefinitions (ExistingPPOpts, ExistingMacros, &ExistingMacroNames);
671
-
672
- // Use a line marker to enter the <command line> file, as the defines and
673
- // undefines here will have come from the command line.
674
- SuggestedPredefines += " # 1 \" <command line>\" 1\n " ;
675
-
676
- for (unsigned I = 0 , N = ExistingMacroNames.size (); I != N; ++I) {
677
- // Dig out the macro definition in the existing preprocessor options.
678
- StringRef MacroName = ExistingMacroNames[I];
679
- std::pair<StringRef, bool > Existing = ExistingMacros[MacroName];
680
-
681
- // Check whether we know anything about this macro name or not.
682
- llvm::StringMap<std::pair<StringRef, bool /* IsUndef*/ >>::iterator Known =
683
- ASTFileMacros.find (MacroName);
684
- if (Validation == OptionValidateNone || Known == ASTFileMacros.end ()) {
685
- if (Validation == OptionValidateStrictMatches) {
686
- // If strict matches are requested, don't tolerate any extra defines on
687
- // the command line that are missing in the AST file.
666
+ if (ReadMacros) {
667
+ // Check macro definitions.
668
+ MacroDefinitionsMap ASTFileMacros;
669
+ collectMacroDefinitions (PPOpts, ASTFileMacros);
670
+ MacroDefinitionsMap ExistingMacros;
671
+ SmallVector<StringRef, 4 > ExistingMacroNames;
672
+ collectMacroDefinitions (ExistingPPOpts, ExistingMacros,
673
+ &ExistingMacroNames);
674
+
675
+ // Use a line marker to enter the <command line> file, as the defines and
676
+ // undefines here will have come from the command line.
677
+ SuggestedPredefines += " # 1 \" <command line>\" 1\n " ;
678
+
679
+ for (unsigned I = 0 , N = ExistingMacroNames.size (); I != N; ++I) {
680
+ // Dig out the macro definition in the existing preprocessor options.
681
+ StringRef MacroName = ExistingMacroNames[I];
682
+ std::pair<StringRef, bool > Existing = ExistingMacros[MacroName];
683
+
684
+ // Check whether we know anything about this macro name or not.
685
+ llvm::StringMap<std::pair<StringRef, bool /* IsUndef*/ >>::iterator Known =
686
+ ASTFileMacros.find (MacroName);
687
+ if (Validation == OptionValidateNone || Known == ASTFileMacros.end ()) {
688
+ if (Validation == OptionValidateStrictMatches) {
689
+ // If strict matches are requested, don't tolerate any extra defines
690
+ // on the command line that are missing in the AST file.
691
+ if (Diags) {
692
+ Diags->Report (diag::err_pch_macro_def_undef) << MacroName << true ;
693
+ }
694
+ return true ;
695
+ }
696
+ // FIXME: Check whether this identifier was referenced anywhere in the
697
+ // AST file. If so, we should reject the AST file. Unfortunately, this
698
+ // information isn't in the control block. What shall we do about it?
699
+
700
+ if (Existing.second ) {
701
+ SuggestedPredefines += " #undef " ;
702
+ SuggestedPredefines += MacroName.str ();
703
+ SuggestedPredefines += ' \n ' ;
704
+ } else {
705
+ SuggestedPredefines += " #define " ;
706
+ SuggestedPredefines += MacroName.str ();
707
+ SuggestedPredefines += ' ' ;
708
+ SuggestedPredefines += Existing.first .str ();
709
+ SuggestedPredefines += ' \n ' ;
710
+ }
711
+ continue ;
712
+ }
713
+
714
+ // If the macro was defined in one but undef'd in the other, we have a
715
+ // conflict.
716
+ if (Existing.second != Known->second .second ) {
688
717
if (Diags) {
689
- Diags->Report (diag::err_pch_macro_def_undef) << MacroName << true ;
718
+ Diags->Report (diag::err_pch_macro_def_undef)
719
+ << MacroName << Known->second .second ;
690
720
}
691
721
return true ;
692
722
}
693
- // FIXME: Check whether this identifier was referenced anywhere in the
694
- // AST file. If so, we should reject the AST file. Unfortunately, this
695
- // information isn't in the control block. What shall we do about it?
696
-
697
- if (Existing.second ) {
698
- SuggestedPredefines += " #undef " ;
699
- SuggestedPredefines += MacroName.str ();
700
- SuggestedPredefines += ' \n ' ;
701
- } else {
702
- SuggestedPredefines += " #define " ;
703
- SuggestedPredefines += MacroName.str ();
704
- SuggestedPredefines += ' ' ;
705
- SuggestedPredefines += Existing.first .str ();
706
- SuggestedPredefines += ' \n ' ;
723
+
724
+ // If the macro was #undef'd in both, or if the macro bodies are
725
+ // identical, it's fine.
726
+ if (Existing.second || Existing.first == Known->second .first ) {
727
+ ASTFileMacros.erase (Known);
728
+ continue ;
707
729
}
708
- continue ;
709
- }
710
730
711
- // If the macro was defined in one but undef'd in the other, we have a
712
- // conflict.
713
- if (Existing.second != Known->second .second ) {
731
+ // The macro bodies differ; complain.
714
732
if (Diags) {
715
- Diags->Report (diag::err_pch_macro_def_undef )
716
- << MacroName << Known->second .second ;
733
+ Diags->Report (diag::err_pch_macro_def_conflict )
734
+ << MacroName << Known->second .first << Existing. first ;
717
735
}
718
736
return true ;
719
737
}
720
738
721
- // If the macro was #undef'd in both, or if the macro bodies are identical,
722
- // it's fine.
723
- if (Existing.second || Existing.first == Known->second .first ) {
724
- ASTFileMacros.erase (Known);
725
- continue ;
726
- }
727
-
728
- // The macro bodies differ; complain.
729
- if (Diags) {
730
- Diags->Report (diag::err_pch_macro_def_conflict)
731
- << MacroName << Known->second .first << Existing.first ;
732
- }
733
- return true ;
734
- }
735
-
736
- // Leave the <command line> file and return to <built-in>.
737
- SuggestedPredefines += " # 1 \" <built-in>\" 2\n " ;
739
+ // Leave the <command line> file and return to <built-in>.
740
+ SuggestedPredefines += " # 1 \" <built-in>\" 2\n " ;
738
741
739
- if (Validation == OptionValidateStrictMatches) {
740
- // If strict matches are requested, don't tolerate any extra defines in
741
- // the AST file that are missing on the command line.
742
- for (const auto &MacroName : ASTFileMacros.keys ()) {
743
- if (Diags) {
744
- Diags->Report (diag::err_pch_macro_def_undef) << MacroName << false ;
742
+ if (Validation == OptionValidateStrictMatches) {
743
+ // If strict matches are requested, don't tolerate any extra defines in
744
+ // the AST file that are missing on the command line.
745
+ for (const auto &MacroName : ASTFileMacros.keys ()) {
746
+ if (Diags) {
747
+ Diags->Report (diag::err_pch_macro_def_undef) << MacroName << false ;
748
+ }
749
+ return true ;
745
750
}
746
- return true ;
747
751
}
748
752
}
749
753
@@ -805,24 +809,22 @@ static bool checkPreprocessorOptions(
805
809
}
806
810
807
811
bool PCHValidator::ReadPreprocessorOptions (const PreprocessorOptions &PPOpts,
808
- bool Complain,
812
+ bool ReadMacros, bool Complain,
809
813
std::string &SuggestedPredefines) {
810
814
const PreprocessorOptions &ExistingPPOpts = PP.getPreprocessorOpts ();
811
815
812
- return checkPreprocessorOptions (PPOpts, ExistingPPOpts,
813
- Complain? &Reader.Diags : nullptr ,
814
- PP.getFileManager (),
815
- SuggestedPredefines,
816
- PP.getLangOpts ());
816
+ return checkPreprocessorOptions (
817
+ PPOpts, ExistingPPOpts, ReadMacros, Complain ? &Reader.Diags : nullptr ,
818
+ PP.getFileManager (), SuggestedPredefines, PP.getLangOpts ());
817
819
}
818
820
819
821
bool SimpleASTReaderListener::ReadPreprocessorOptions (
820
- const PreprocessorOptions &PPOpts,
821
- bool Complain,
822
- std::string &SuggestedPredefines) {
823
- return checkPreprocessorOptions (PPOpts , PP.getPreprocessorOpts (), nullptr ,
824
- PP.getFileManager (), SuggestedPredefines ,
825
- PP. getLangOpts (), OptionValidateNone);
822
+ const PreprocessorOptions &PPOpts, bool ReadMacros, bool Complain ,
823
+ std::string &SuggestedPredefines) {
824
+ return checkPreprocessorOptions (PPOpts, PP. getPreprocessorOpts (), ReadMacros,
825
+ nullptr , PP.getFileManager () ,
826
+ SuggestedPredefines, PP.getLangOpts () ,
827
+ OptionValidateNone);
826
828
}
827
829
828
830
// / Check the header search options deserialized from the control block
@@ -5274,10 +5276,10 @@ namespace {
5274
5276
}
5275
5277
5276
5278
bool ReadPreprocessorOptions (const PreprocessorOptions &PPOpts,
5277
- bool Complain,
5279
+ bool ReadMacros, bool Complain,
5278
5280
std::string &SuggestedPredefines) override {
5279
5281
return checkPreprocessorOptions (
5280
- PPOpts, ExistingPPOpts, /* Diags=*/ nullptr , FileMgr,
5282
+ PPOpts, ExistingPPOpts, ReadMacros, /* Diags=*/ nullptr , FileMgr,
5281
5283
SuggestedPredefines, ExistingLangOpts,
5282
5284
StrictOptionMatches ? OptionValidateStrictMatches
5283
5285
: OptionValidateContradictions);
@@ -6048,10 +6050,13 @@ bool ASTReader::ParsePreprocessorOptions(const RecordData &Record,
6048
6050
unsigned Idx = 0 ;
6049
6051
6050
6052
// Macro definitions/undefs
6051
- for (unsigned N = Record[Idx++]; N; --N) {
6052
- std::string Macro = ReadString (Record, Idx);
6053
- bool IsUndef = Record[Idx++];
6054
- PPOpts.Macros .push_back (std::make_pair (Macro, IsUndef));
6053
+ bool ReadMacros = Record[Idx++];
6054
+ if (ReadMacros) {
6055
+ for (unsigned N = Record[Idx++]; N; --N) {
6056
+ std::string Macro = ReadString (Record, Idx);
6057
+ bool IsUndef = Record[Idx++];
6058
+ PPOpts.Macros .push_back (std::make_pair (Macro, IsUndef));
6059
+ }
6055
6060
}
6056
6061
6057
6062
// Includes
@@ -6070,7 +6075,7 @@ bool ASTReader::ParsePreprocessorOptions(const RecordData &Record,
6070
6075
PPOpts.ObjCXXARCStandardLibrary =
6071
6076
static_cast <ObjCXXARCStandardLibraryKind>(Record[Idx++]);
6072
6077
SuggestedPredefines.clear ();
6073
- return Listener.ReadPreprocessorOptions (PPOpts, Complain,
6078
+ return Listener.ReadPreprocessorOptions (PPOpts, ReadMacros, Complain,
6074
6079
SuggestedPredefines);
6075
6080
}
6076
6081
0 commit comments