[PATCH] D128098: [clang][driver] Ensure we don't accumulate entries in -MJ files

Jan Svoboda via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 17 15:01:07 PDT 2022


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG92c6ffa14cde: [clang][driver] Ensure we don't accumulate entries in -MJ files (authored by jansvoboda11).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128098/new/

https://reviews.llvm.org/D128098

Files:
  clang/lib/Driver/Driver.cpp
  clang/test/Driver/compilation_database_multiarch.c


Index: clang/test/Driver/compilation_database_multiarch.c
===================================================================
--- clang/test/Driver/compilation_database_multiarch.c
+++ clang/test/Driver/compilation_database_multiarch.c
@@ -2,7 +2,14 @@
 
 // RUN: rm -rf %t && mkdir -p %t
 // RUN: %clang -fdriver-only -o %t/out %s -mtargetos=macos12 -arch arm64 -arch x86_64 -MJ %t/compilation_database.json
+
+// Let's run that again and verify we're not accumulating redundant entries in the same file.
+//
+// RUN: %clang -fdriver-only -o %t/out %s -mtargetos=macos12 -arch arm64 -arch x86_64 -MJ %t/compilation_database.json
+// RUN: echo EOF >> %t/compilation_database.json
+
 // RUN: FileCheck --input-file=%t/compilation_database.json %s
 
 // CHECK:      { "directory": "{{.*}}", "file": "{{.*}}", "output": "[[OUTPUT_X86_64:.*]]", "arguments": [{{.*}}, "-o", "[[OUTPUT_X86_64]]", {{.*}} "--target=x86_64-apple-macosx12.0.0"]},
 // CHECK-NEXT: { "directory": "{{.*}}", "file": "{{.*}}", "output": "[[OUTPUT_ARM64:.*]]", "arguments": [{{.*}}, "-o", "[[OUTPUT_ARM64]]", {{.*}} "--target=arm64-apple-macosx12.0.0"]},
+// CHECK-NEXT: EOF
Index: clang/lib/Driver/Driver.cpp
===================================================================
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -1314,6 +1314,10 @@
       BitcodeEmbed = static_cast<BitcodeEmbedMode>(Model);
   }
 
+  // Remove existing compilation database so that each job can append to it.
+  if (Arg *A = Args.getLastArg(options::OPT_MJ))
+    llvm::sys::fs::remove(A->getValue());
+
   // Setting up the jobs for some precompile cases depends on whether we are
   // treating them as PCH, implicit modules or C++20 ones.
   // TODO: inferring the mode like this seems fragile (it meets the objective


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D128098.438047.patch
Type: text/x-patch
Size: 1790 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220617/c23f49e9/attachment-0001.bin>


More information about the cfe-commits mailing list