Skip to content

Commit f41ec70

Browse files
committed
[Clang][Driver] Remove -M group options before generating crash diagnostics
Previously, when using '-MF file.d' on the command line, 'file.d' would not be deleted after a compiler crash. The code path in Compilation::initCompilationForDiagnostics() that was modifying 'TranslatedArgs' had no effect, because 'TCArgs' was already created after the crash. This was covered by clang/test/Driver/output-file-cleanup.c, the test was succeeding by fluke because Driver::generateCompilationDiagnostics() would fail to launch the subsequent clang -E (see D74070 for a fix for this). So the test was only covering Driver.cpp, C.CleanupFileMap(). After this patch, both cleanup and removal of -MF are exercised. Differential Revision: https://reviews.llvm.org/D74076
1 parent 5fedc2b commit f41ec70

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

clang/lib/Driver/Compilation.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,14 +258,23 @@ void Compilation::initCompilationForDiagnostics() {
258258

259259
// Remove any user specified output. Claim any unclaimed arguments, so as
260260
// to avoid emitting warnings about unused args.
261-
OptSpecifier OutputOpts[] = { options::OPT_o, options::OPT_MD,
262-
options::OPT_MMD };
261+
OptSpecifier OutputOpts[] = {
262+
options::OPT_o, options::OPT_MD, options::OPT_MMD, options::OPT_M,
263+
options::OPT_MM, options::OPT_MF, options::OPT_MG, options::OPT_MJ,
264+
options::OPT_MQ, options::OPT_MT, options::OPT_MV};
263265
for (unsigned i = 0, e = llvm::array_lengthof(OutputOpts); i != e; ++i) {
264266
if (TranslatedArgs->hasArg(OutputOpts[i]))
265267
TranslatedArgs->eraseArg(OutputOpts[i]);
266268
}
267269
TranslatedArgs->ClaimAllArgs();
268270

271+
// Force re-creation of the toolchain Args, otherwise our modifications just
272+
// above will have no effect.
273+
for (auto Arg : TCArgs)
274+
if (Arg.second != TranslatedArgs)
275+
delete Arg.second;
276+
TCArgs.clear();
277+
269278
// Redirect stdout/stderr to /dev/null.
270279
Redirects = {None, {""}, {""}};
271280

clang/test/Driver/output-file-cleanup.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11

2-
// Temporarily disable this test until the -MF flag is properly removed from the diagnostics generation.
3-
// XFAIL: *
4-
52
// RUN: rm -f "%t.d" "%t1.s" "%t2.s" "%t3.s" "%t4.s" "%t5.s"
63
//
74
// RUN: touch %t.s

0 commit comments

Comments
 (0)