Author: Alexandre Ganea Date: 2020-02-06T16:23:25-05:00 New Revision: f41ec709d9d388dc43469e6ac7f51b6313f7e4af
URL: https://github.com/llvm/llvm-project/commit/f41ec709d9d388dc43469e6ac7f51b6313f7e4af DIFF: https://github.com/llvm/llvm-project/commit/f41ec709d9d388dc43469e6ac7f51b6313f7e4af.diff LOG: [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 Added: Modified: clang/lib/Driver/Compilation.cpp clang/test/Driver/output-file-cleanup.c Removed: ################################################################################ diff --git a/clang/lib/Driver/Compilation.cpp b/clang/lib/Driver/Compilation.cpp index 25aec3690f21..52477576b2eb 100644 --- a/clang/lib/Driver/Compilation.cpp +++ b/clang/lib/Driver/Compilation.cpp @@ -258,14 +258,23 @@ void Compilation::initCompilationForDiagnostics() { // Remove any user specified output. Claim any unclaimed arguments, so as // to avoid emitting warnings about unused args. - OptSpecifier OutputOpts[] = { options::OPT_o, options::OPT_MD, - options::OPT_MMD }; + OptSpecifier OutputOpts[] = { + options::OPT_o, options::OPT_MD, options::OPT_MMD, options::OPT_M, + options::OPT_MM, options::OPT_MF, options::OPT_MG, options::OPT_MJ, + options::OPT_MQ, options::OPT_MT, options::OPT_MV}; for (unsigned i = 0, e = llvm::array_lengthof(OutputOpts); i != e; ++i) { if (TranslatedArgs->hasArg(OutputOpts[i])) TranslatedArgs->eraseArg(OutputOpts[i]); } TranslatedArgs->ClaimAllArgs(); + // Force re-creation of the toolchain Args, otherwise our modifications just + // above will have no effect. + for (auto Arg : TCArgs) + if (Arg.second != TranslatedArgs) + delete Arg.second; + TCArgs.clear(); + // Redirect stdout/stderr to /dev/null. Redirects = {None, {""}, {""}}; diff --git a/clang/test/Driver/output-file-cleanup.c b/clang/test/Driver/output-file-cleanup.c index 4dcb5ae5d938..c572b25cecef 100644 --- a/clang/test/Driver/output-file-cleanup.c +++ b/clang/test/Driver/output-file-cleanup.c @@ -1,7 +1,4 @@ -// Temporarily disable this test until the -MF flag is properly removed from the diagnostics generation. -// XFAIL: * - // RUN: rm -f "%t.d" "%t1.s" "%t2.s" "%t3.s" "%t4.s" "%t5.s" // // RUN: touch %t.s _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits