Index: clang/lib/Driver/ToolChains/Clang.cpp =================================================================== --- clang/lib/Driver/ToolChains/Clang.cpp +++ clang/lib/Driver/ToolChains/Clang.cpp @@ -2426,7 +2426,8 @@ CWD = "."; CDB << "{ \"directory\": \"" << escape(*CWD) << "\""; CDB << ", \"file\": \"" << escape(Input.getFilename()) << "\""; - CDB << ", \"output\": \"" << escape(Output.getFilename()) << "\""; + if (Output.isFilename()) + CDB << ", \"output\": \"" << escape(Output.getFilename()) << "\""; CDB << ", \"arguments\": [\"" << escape(D.ClangExecutable) << "\""; SmallString<128> Buf; Buf = "-x"; @@ -2438,7 +2439,8 @@ CDB << ", \"" << escape(Buf) << "\""; } CDB << ", \"" << escape(Input.getFilename()) << "\""; - CDB << ", \"-o\", \"" << escape(Output.getFilename()) << "\""; + if (Output.isFilename()) + CDB << ", \"-o\", \"" << escape(Output.getFilename()) << "\""; for (auto &A: Args) { auto &O = A->getOption(); // Skip language selection, which is positional. Index: clang/test/Driver/compilation_database_fsyntax_only.c =================================================================== --- /dev/null +++ clang/test/Driver/compilation_database_fsyntax_only.c @@ -0,0 +1,16 @@ +// RUN: mkdir -p %t.workdir && cd %t.workdir +// RUN: %clang -fsyntax-only %s -MJ - 2>&1 | FileCheck %s + +// CHECK: { +// CHECK-SAME: "directory": "{{[^"]*}}workdir", +// CHECK-SAME: "file": "{{[^"]*}}compilation_database_fsyntax_only.c" +// CHECK-NOT: "output" +// CHECK-SAME: "arguments": [ +// CHECK-NOT: "-o" +// CHECK-SAME: ] +// CHECK-SAME: } + + +int main(void) { + return 0; +}