[clang] [clang][dataflow] In tests, error out if we didn't find any matching target functions. (PR #66197)

via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 13 06:10:02 PDT 2023


https://github.com/martinboehme updated https://github.com/llvm/llvm-project/pull/66197:

>From 8285300a8b3960e1629287e3c173fd4c6b33b9f8 Mon Sep 17 00:00:00 2001
From: Martin Braenne <mboehme at google.com>
Date: Wed, 13 Sep 2023 11:57:16 +0000
Subject: [PATCH] [clang][dataflow] In tests, error out if we didn't find any
 matching target functions.

Before, we were silently letting the test pass, which masks test bugs; for an
example, see https://github.com/llvm/llvm-project/pull/66195.
---
 .../Analysis/FlowSensitive/TestingSupport.h       | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/clang/unittests/Analysis/FlowSensitive/TestingSupport.h b/clang/unittests/Analysis/FlowSensitive/TestingSupport.h
index 0cf66c218f43fdc..44d962d5da9a97b 100644
--- a/clang/unittests/Analysis/FlowSensitive/TestingSupport.h
+++ b/clang/unittests/Analysis/FlowSensitive/TestingSupport.h
@@ -240,12 +240,15 @@ checkDataflow(AnalysisInputs<AnalysisT> AI,
     };
   }
 
-  for (const ast_matchers::BoundNodes &BN :
-       ast_matchers::match(ast_matchers::functionDecl(
-                               ast_matchers::hasBody(ast_matchers::stmt()),
-                               AI.TargetFuncMatcher)
-                               .bind("target"),
-                           Context)) {
+  SmallVector<ast_matchers::BoundNodes, 1> MatchResult = ast_matchers::match(
+      ast_matchers::functionDecl(ast_matchers::hasBody(ast_matchers::stmt()),
+                                 AI.TargetFuncMatcher)
+          .bind("target"),
+      Context);
+  if (MatchResult.empty())
+    return llvm::createStringError(llvm::inconvertibleErrorCode(),
+                                   "didn't find any matching target functions");
+  for (const ast_matchers::BoundNodes &BN : MatchResult) {
     // Get the AST node of the target function.
     const FunctionDecl *Target = BN.getNodeAs<FunctionDecl>("target");
     if (Target == nullptr)



More information about the cfe-commits mailing list