Index: lib/Driver/ToolChains/Clang.cpp =================================================================== --- lib/Driver/ToolChains/Clang.cpp +++ lib/Driver/ToolChains/Clang.cpp @@ -1910,8 +1910,9 @@ void Clang::DumpCompilationDatabase(Compilation &C, StringRef Filename, StringRef Target, const InputInfo &Output, const InputInfo &Input, const ArgList &Args) const { - // If this is a dry run, do not create the compilation database file. - if (C.getArgs().hasArg(options::OPT__HASH_HASH_HASH)) + // If this is a dry run or a pre-processing-only run, then do not create the + // compilation database file. + if (C.getArgs().hasArg(options::OPT__HASH_HASH_HASH, options::OPT_E)) return; using llvm::yaml::escape; Index: test/Driver/compilation_database.c =================================================================== --- test/Driver/compilation_database.c +++ test/Driver/compilation_database.c @@ -1,6 +1,10 @@ // 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 -E -c -x c %s -MJ E.json +// RUN: test ! -f E.json +// RUN: %clang -### -c -x c %s -MJ hash_hash_hash.json +// RUN: test ! -f hash_hash_hash.json // 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={{[^"]+}}"]},