Index: lib/Driver/ToolChains/Clang.cpp =================================================================== --- lib/Driver/ToolChains/Clang.cpp +++ lib/Driver/ToolChains/Clang.cpp @@ -1856,7 +1856,8 @@ Buf = "."; CDB << "{ \"directory\": \"" << escape(Buf) << "\""; CDB << ", \"file\": \"" << escape(Input.getFilename()) << "\""; - CDB << ", \"output\": \"" << escape(Output.getFilename()) << "\""; + if (!Output.isNothing()) + CDB << ", \"output\": \"" << escape(Output.getFilename()) << "\""; CDB << ", \"arguments\": [\"" << escape(D.ClangExecutable) << "\""; Buf = "-x"; Buf += types::getTypeName(Input.getType()); Index: test/Driver/compilation_database.c =================================================================== --- test/Driver/compilation_database.c +++ test/Driver/compilation_database.c @@ -1,10 +1,12 @@ // RUN: mkdir -p %t && cd %t // RUN: %clang -MD -MP --sysroot=somewhere -c -x c %s -xc++ %s -Wall -MJ - -no-canonical-prefixes 2>&1 | FileCheck %s // RUN: not %clang -c -x c %s -MJ %s/non-existant -no-canonical-prefixes 2>&1 | FileCheck --check-prefix=ERROR %s +// RUN: %clang %s --sysroot=somewhere -MJ - -fsyntax-only -no-canonical-prefixes 2>&1 | FileCheck --check-prefix=FSYNTAX-ONLY %s // CHECK: { "directory": "{{.*}}", "file": "[[SRC:[^"]+[/|\\]compilation_database.c]]", "output": "compilation_database.o", "arguments": ["{{[^"]*}}clang{{[^"]*}}", "-xc", "[[SRC]]", "--sysroot=somewhere", "-c", "-Wall",{{.*}} "--target={{[^"]+}}"]}, // CHECK: { "directory": "{{.*}}", "file": "[[SRC:[^"]+[/|\\]compilation_database.c]]", "output": "compilation_database.o", "arguments": ["{{[^"]*}}clang{{[^"]*}}", "-xc++", "[[SRC]]", "--sysroot=somewhere", "-c", "-Wall",{{.*}} "--target={{[^"]+}}"]}, // ERROR: error: compilation database '{{.*}}/non-existant' could not be opened: +// FSYNTAX-ONLY: { "directory": "{{.*}}", "file": "[[SRC:[^"]+[/|\\]compilation_database.c]]", "arguments": ["{{[^"]*}}clang{{[^"]*}}", "-xc", "[[SRC]]", "--sysroot=somewhere", {{.*}} "--target={{[^"]+}}"]}, int main(void) { return 0;