[PATCH] D54109: [clang-query] continue even if files are skipped

Peter Wu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 5 08:40:03 PST 2018


Lekensteyn created this revision.
Lekensteyn added reviewers: cfe-commits, pcc.

Like clang-check, continue even if some source files were not found in
the compilation database. This makes it possible to do search for
matching sources and query files that exist in the compilation db:

  clang-query -c 'm callExpr(callee(functionDecl(hasName("function_name"))))' $(grep -rl ^function_name)

Note: buildASTs calls ClangTool::run which returns 1 if any of the
commands failed and 2 otherwise if any of the files were missing.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D54109

Files:
  clang-query/tool/ClangQuery.cpp
  test/clang-query/Inputs/database_template.json
  test/clang-query/database-missing-entry.c


Index: test/clang-query/database-missing-entry.c
===================================================================
--- /dev/null
+++ test/clang-query/database-missing-entry.c
@@ -0,0 +1,12 @@
+// 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: 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: Skipping {{.*[/\\]}}missing.c. Compile command not found.
+// CHECK-NOT-EXIST: Error while processing {{.*[/\\]}}missing.c.
+// CHECK-NOT-EXIST: unable to handle compilation
+// CHECK: a.c:1:9: note: "root" binds here
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: clang-query/tool/ClangQuery.cpp
===================================================================
--- clang-query/tool/ClangQuery.cpp
+++ clang-query/tool/ClangQuery.cpp
@@ -100,8 +100,7 @@
   ClangTool Tool(OptionsParser.getCompilations(),
                  OptionsParser.getSourcePathList());
   std::vector<std::unique_ptr<ASTUnit>> ASTs;
-  if (Tool.buildASTs(ASTs) != 0)
-    return 1;
+  Tool.buildASTs(ASTs);
 
   QuerySession QS(ASTs);
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D54109.172596.patch
Type: text/x-patch
Size: 1819 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181105/0f2bb1b7/attachment.bin>


More information about the cfe-commits mailing list