[PATCH] D74076: [Clang][Driver] Remove -M group options before generating crash diagnostics

Alexandre Ganea via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 5 10:24:40 PST 2020


aganea created this revision.
aganea added reviewers: hans, rnk.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
aganea edited the summary of this revision.

When using `-MF file.d` on the command line, `file.d` would not be deleted after a compiler crash.

Previously, the code path below had no effect, because `TCArgs` was already created after the crash, thus changes to `TranslatedArgs` would have no effect.

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 <https://reviews.llvm.org/D74070> for a fix for this). So the test was only covering code in `Driver.cpp, L1492 and L1496` (`C.CleanupFileMap`). After this patch, both cleanup and removal of `-MF` are exercised.

//This patch is point 2. in D73742 <https://reviews.llvm.org/D73742>//


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D74076

Files:
  clang/lib/Driver/Compilation.cpp


Index: clang/lib/Driver/Compilation.cpp
===================================================================
--- clang/lib/Driver/Compilation.cpp
+++ clang/lib/Driver/Compilation.cpp
@@ -258,14 +258,23 @@
 
   // 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, {""}, {""}};
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D74076.242676.patch
Type: text/x-patch
Size: 1219 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200205/bfb2706f/attachment-0001.bin>


More information about the cfe-commits mailing list