@@ -160,6 +160,26 @@ void ModuleDepCollector::addOutputPaths(CowCompilerInvocation &CI,
160160 }
161161}
162162
163+ void dependencies::resetBenignCodeGenOptions (frontend::ActionKind ProgramAction,
164+ const LangOptions &LangOpts,
165+ CodeGenOptions &CGOpts) {
166+ // TODO: Figure out better way to set options to their default value.
167+ if (ProgramAction == frontend::GenerateModule) {
168+ CGOpts.MainFileName .clear ();
169+ CGOpts.DwarfDebugFlags .clear ();
170+ }
171+ if (ProgramAction == frontend::GeneratePCH ||
172+ (ProgramAction == frontend::GenerateModule && !LangOpts.ModulesCodegen )) {
173+ CGOpts.DebugCompilationDir .clear ();
174+ CGOpts.CoverageCompilationDir .clear ();
175+ CGOpts.CoverageDataFile .clear ();
176+ CGOpts.CoverageNotesFile .clear ();
177+ CGOpts.ProfileInstrumentUsePath .clear ();
178+ CGOpts.SampleProfileFile .clear ();
179+ CGOpts.ProfileRemappingFile .clear ();
180+ }
181+ }
182+
163183static CowCompilerInvocation
164184makeCommonInvocationForModuleBuild (CompilerInvocation CI) {
165185 CI.resetNonModularOptions ();
@@ -176,18 +196,8 @@ makeCommonInvocationForModuleBuild(CompilerInvocation CI) {
176196 // LLVM options are not going to affect the AST
177197 CI.getFrontendOpts ().LLVMArgs .clear ();
178198
179- // TODO: Figure out better way to set options to their default value.
180- CI.getCodeGenOpts ().MainFileName .clear ();
181- CI.getCodeGenOpts ().DwarfDebugFlags .clear ();
182- if (!CI.getLangOpts ().ModulesCodegen ) {
183- CI.getCodeGenOpts ().DebugCompilationDir .clear ();
184- CI.getCodeGenOpts ().CoverageCompilationDir .clear ();
185- CI.getCodeGenOpts ().CoverageDataFile .clear ();
186- CI.getCodeGenOpts ().CoverageNotesFile .clear ();
187- CI.getCodeGenOpts ().ProfileInstrumentUsePath .clear ();
188- CI.getCodeGenOpts ().SampleProfileFile .clear ();
189- CI.getCodeGenOpts ().ProfileRemappingFile .clear ();
190- }
199+ resetBenignCodeGenOptions (frontend::GenerateModule, CI.getLangOpts (),
200+ CI.getCodeGenOpts ());
191201
192202 // Map output paths that affect behaviour to "-" so their existence is in the
193203 // context hash. The final path will be computed in addOutputPaths.
@@ -371,6 +381,8 @@ static bool needsModules(FrontendInputFile FIF) {
371381
372382void ModuleDepCollector::applyDiscoveredDependencies (CompilerInvocation &CI) {
373383 CI.clearImplicitModuleBuildOptions ();
384+ resetBenignCodeGenOptions (CI.getFrontendOpts ().ProgramAction ,
385+ CI.getLangOpts (), CI.getCodeGenOpts ());
374386
375387 if (llvm::any_of (CI.getFrontendOpts ().Inputs , needsModules)) {
376388 Preprocessor &PP = ScanInstance.getPreprocessor ();
0 commit comments