Skip to content

Commit f96eadb

Browse files
committed
[clang/DependencyScanning/ModuleDepCollector] Refactor part of makeCommonInvocationForModuleBuild into its own function, NFC
The new function is about clearing out benign codegen options and is a bit more general.
1 parent a952c12 commit f96eadb

File tree

2 files changed

+27
-12
lines changed

2 files changed

+27
-12
lines changed

clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,11 @@ class ModuleDepCollector final : public DependencyCollector {
308308
ModuleDeps &Deps);
309309
};
310310

311+
/// Resets codegen options that don't affect modules/PCH.
312+
void resetBenignCodeGenOptions(frontend::ActionKind ProgramAction,
313+
const LangOptions &LangOpts,
314+
CodeGenOptions &CGOpts);
315+
311316
} // end namespace dependencies
312317
} // end namespace tooling
313318
} // end namespace clang

clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
157177
static CowCompilerInvocation
158178
makeCommonInvocationForModuleBuild(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.

0 commit comments

Comments
 (0)