@@ -154,6 +154,26 @@ void ModuleDepCollector::addOutputPaths(CowCompilerInvocation &CI,
154154 }
155155}
156156
157+ void dependencies::resetBenignCodeGenOptions (frontend::ActionKind ProgramAction,
158+ const LangOptions &LangOpts,
159+ CodeGenOptions &CGOpts) {
160+ // TODO: Figure out better way to set options to their default value.
161+ if (ProgramAction == frontend::GenerateModule) {
162+ CGOpts.MainFileName .clear ();
163+ CGOpts.DwarfDebugFlags .clear ();
164+ }
165+ if (ProgramAction == frontend::GeneratePCH ||
166+ (ProgramAction == frontend::GenerateModule && !LangOpts.ModulesCodegen )) {
167+ CGOpts.DebugCompilationDir .clear ();
168+ CGOpts.CoverageCompilationDir .clear ();
169+ CGOpts.CoverageDataFile .clear ();
170+ CGOpts.CoverageNotesFile .clear ();
171+ CGOpts.ProfileInstrumentUsePath .clear ();
172+ CGOpts.SampleProfileFile .clear ();
173+ CGOpts.ProfileRemappingFile .clear ();
174+ }
175+ }
176+
157177static CowCompilerInvocation
158178makeCommonInvocationForModuleBuild (CompilerInvocation CI) {
159179 CI.resetNonModularOptions ();
@@ -167,18 +187,8 @@ makeCommonInvocationForModuleBuild(CompilerInvocation CI) {
167187 // LLVM options are not going to affect the AST
168188 CI.getFrontendOpts ().LLVMArgs .clear ();
169189
170- // TODO: Figure out better way to set options to their default value.
171- CI.getCodeGenOpts ().MainFileName .clear ();
172- CI.getCodeGenOpts ().DwarfDebugFlags .clear ();
173- if (!CI.getLangOpts ().ModulesCodegen ) {
174- CI.getCodeGenOpts ().DebugCompilationDir .clear ();
175- CI.getCodeGenOpts ().CoverageCompilationDir .clear ();
176- CI.getCodeGenOpts ().CoverageDataFile .clear ();
177- CI.getCodeGenOpts ().CoverageNotesFile .clear ();
178- CI.getCodeGenOpts ().ProfileInstrumentUsePath .clear ();
179- CI.getCodeGenOpts ().SampleProfileFile .clear ();
180- CI.getCodeGenOpts ().ProfileRemappingFile .clear ();
181- }
190+ resetBenignCodeGenOptions (frontend::GenerateModule, CI.getLangOpts (),
191+ CI.getCodeGenOpts ());
182192
183193 // Map output paths that affect behaviour to "-" so their existence is in the
184194 // context hash. The final path will be computed in addOutputPaths.
@@ -342,6 +352,8 @@ static bool needsModules(FrontendInputFile FIF) {
342352
343353void ModuleDepCollector::applyDiscoveredDependencies (CompilerInvocation &CI) {
344354 CI.clearImplicitModuleBuildOptions ();
355+ resetBenignCodeGenOptions (CI.getFrontendOpts ().ProgramAction ,
356+ CI.getLangOpts (), CI.getCodeGenOpts ());
345357
346358 if (llvm::any_of (CI.getFrontendOpts ().Inputs , needsModules)) {
347359 Preprocessor &PP = ScanInstance.getPreprocessor ();
0 commit comments