diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -2382,7 +2382,8 @@ if (!CompilationDatabase) { std::error_code EC; auto File = std::make_unique( - Filename, EC, llvm::sys::fs::OF_TextWithCRLF); + Filename, EC, + llvm::sys::fs::OF_TextWithCRLF | llvm::sys::fs::OF_Append); if (EC) { D.Diag(clang::diag::err_drv_compilationdatabase) << Filename << EC.message(); diff --git a/clang/test/Driver/compilation_database_multiarch.c b/clang/test/Driver/compilation_database_multiarch.c new file mode 100644 --- /dev/null +++ b/clang/test/Driver/compilation_database_multiarch.c @@ -0,0 +1,6 @@ +// RUN: rm -rf %t && mkdir -p %t +// RUN: %clang -c %s -o %t/out -target x86_64-apple-darwin -arch x86_64 -arch arm64 -MJ %t/compilation_database.json +// RUN: FileCheck --input-file=%t/compilation_database.json %s + +// CHECK: { "directory": "{{.*}}", "file": "{{.*}}", "output": "{{.*}}", "arguments": [{{.*}} "--target=x86_64-apple-macosx12.0.0"]}, +// CHECK-NEXT: { "directory": "{{.*}}", "file": "{{.*}}", "output": "{{.*}}", "arguments": [{{.*}} "--target=arm64-apple-ios5.0.0"]},