@@ -87,12 +87,19 @@ static void updateCompilerInvocation(CompilerInvocation &Invocation,
87
87
Invocation.getFrontendOpts ().Inputs .clear ();
88
88
Invocation.getHeaderSearchOpts () = HeaderSearchOptions ();
89
89
auto &PPOpts = Invocation.getPreprocessorOpts ();
90
- // We don't need these because we save the contents of the predefines buffer
91
- // and the PCH file in the include tree root.
92
- PPOpts.Macros .clear ();
93
- PPOpts.MacroIncludes .clear ();
90
+ // We don't need this because we save the contents of the PCH file in the
91
+ // include tree root.
94
92
PPOpts.ImplicitPCHInclude .clear ();
95
- PPOpts.Includes .clear ();
93
+ if (Invocation.getFrontendOpts ().ProgramAction != frontend::GeneratePCH) {
94
+ // We don't need these because we save the contents of the predefines
95
+ // buffer in the include tree. But if we generate a PCH file we still need
96
+ // to keep them as preprocessor options so that they are preserved in a
97
+ // PCH file and compared with the preprocessor options of the dep-scan
98
+ // invocation that uses the PCH.
99
+ PPOpts.Macros .clear ();
100
+ PPOpts.MacroIncludes .clear ();
101
+ PPOpts.Includes .clear ();
102
+ }
96
103
} else {
97
104
FileSystemOpts.CASFileSystemRootID = RootID;
98
105
FileSystemOpts.CASFileSystemWorkingDirectory = CASWorkingDirectory.str ();
@@ -152,6 +159,12 @@ static void updateCompilerInvocation(CompilerInvocation &Invocation,
152
159
remapInPlaceOrFilterOut (HeaderSearchOpts.PrebuiltModulePaths );
153
160
remapInPlaceOrFilterOut (HeaderSearchOpts.VFSOverlayFiles );
154
161
162
+ // Preprocessor options.
163
+ auto &PPOpts = Invocation.getPreprocessorOpts ();
164
+ remapInPlaceOrFilterOut (PPOpts.MacroIncludes );
165
+ remapInPlaceOrFilterOut (PPOpts.Includes );
166
+ Mapper.mapInPlaceOrClear (PPOpts.ImplicitPCHInclude );
167
+
155
168
// Frontend options.
156
169
remapInPlaceOrFilterOutWith (
157
170
FrontendOpts.Inputs , [&](FrontendInputFile &Input) {
0 commit comments