Index: clang-query/tool/ClangQuery.cpp =================================================================== --- clang-query/tool/ClangQuery.cpp +++ clang-query/tool/ClangQuery.cpp @@ -100,8 +100,9 @@ ClangTool Tool(OptionsParser.getCompilations(), OptionsParser.getSourcePathList()); std::vector> ASTs; - if (Tool.buildASTs(ASTs) != 0) - return 1; + int RunResult = Tool.buildASTs(ASTs); + if (ASTs.empty()) + return 1; QuerySession QS(ASTs); @@ -134,5 +135,5 @@ } } - return 0; + return RunResult; } Index: test/clang-query/Inputs/database_template.json =================================================================== --- /dev/null +++ test/clang-query/Inputs/database_template.json @@ -0,0 +1,12 @@ +[ +{ + "directory": "test_dir/build", + "command": "clang -DAVAL=8 -o a.o test_dir/src/a.c", + "file": "test_dir/src/a.c" +}, +{ + "directory": "test_dir/build", + "command": "clang -o b.o test_dir/src/b.c", + "file": "test_dir/src/b.c" +} +] Index: test/clang-query/database-missing-entry.c =================================================================== --- /dev/null +++ test/clang-query/database-missing-entry.c @@ -0,0 +1,16 @@ +// RUN: rm -rf %t && mkdir -p %t/src %t/build +// RUN: sed 's|test_dir|%t|g' %S/Inputs/database_template.json > %t/build/compile_commands.json +// RUN: echo 'int A = AVAL;' > %t/src/a.c +// RUN: echo 'deliberate parsing error' > %t/src/b.c +// RUN: not clang-query -p=%t/build -c "m integerLiteral()" %t/src/a.c %t/src/b.c %t/src/missing.c 2>&1 | FileCheck %s + +// Test that neither parse errors nor missing database entries prevent further processing. +// CHECK: deliberate parsing error +// CHECK: Error while processing {{.*[/\\]}}missing.c. +// CHECK-NOT-EXIST: Error while processing {{.*[/\\]}}missing.c. +// CHECK-NOT-EXIST: unable to handle compilation +// CHECK: a.c:1:9: note: "root" binds here + +// Test that an empty AST due to lack of any source files is bad. +// RUN: not clang-query -p=%t/build -c "m integerLiteral()" %t/src/missing.c 2>&1 | FileCheck --check-prefix=CHECK-NONE %s +// CHECK-NONE: Error while processing {{.*[/\\]}}missing.c.