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

Peter Wu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 6 05:59:25 PST 2018


Lekensteyn updated this revision to Diff 172747.
Lekensteyn retitled this revision from "[clang-query] continue even if files are skipped" to "[clang-query] continue querying even if files are skipped".
Lekensteyn added a comment.

Changes:

- Return 1 (instead of 0) if none of the files could be parsed (and add a test for it)
- Propagate any error code (like 2 in case of some missing files) from `Tool.buildASTs` instead of returning 0.
- Change test to accomodate the change in behavior/output due to https://reviews.llvm.org/D51729 (Thanks to Sam McCall for feedback.)


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,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.
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,9 @@
   ClangTool Tool(OptionsParser.getCompilations(),
                  OptionsParser.getSourcePathList());
   std::vector<std::unique_ptr<ASTUnit>> 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;
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D54109.172747.patch
Type: text/x-patch
Size: 2189 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181106/d75fabc6/attachment.bin>


More information about the cfe-commits mailing list