[all-commits] [llvm/llvm-project] c8b31d: [clang][dataflow] Allow analyzing multiple functio...

Dmitri Gribenko via All-commits all-commits at lists.llvm.org
Fri Jan 20 16:28:18 PST 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: c8b31da1ef0a3f2a0ba5c39bb4281b1438e511fb
      https://github.com/llvm/llvm-project/commit/c8b31da1ef0a3f2a0ba5c39bb4281b1438e511fb
  Author: Dmitri Gribenko <gribozavr at gmail.com>
  Date:   2023-01-21 (Sat, 21 Jan 2023)

  Changed paths:
    M clang/unittests/Analysis/FlowSensitive/TestingSupport.cpp
    M clang/unittests/Analysis/FlowSensitive/TestingSupport.h
    M clang/unittests/Analysis/FlowSensitive/TestingSupportTest.cpp

  Log Message:
  -----------
  [clang][dataflow] Allow analyzing multiple functions in unit tests

In unit tests for concrete dataflow analyses we typically use the
testonly `checkDataflow()` helper to analyse a free function called
"target". This pattern allows our tests to be uniform and focused on
specific statement- or expression-level C++ features.

As we expand our feature coverage, we want to analyze functions whose
names we don't fully control, like constructors, destructors, operators
etc. In such tests it is often convenient to analyze all functions
defined in the input code, to avoid having to carefully craft an AST
matcher that finds the exact function we're interested in. That can be
easily done by providing `checkDataflow()` with a catch-all matcher like
`functionDecl()`.

It is also often convenient to define multiple special member functions
in a single unit test, for example, multiple constructors, and share the
rest of the class definition code between constructors. As a result, it
makes sense to analyze multiple functions in one unit test.

This change allows `checkDataflow()` to correctly handle AST matchers
that match more than one function. Previously, it would only ever
analyze the first matched function, and silently ignore the rest. Now it
runs dataflow analysis in a loop, and calls `VerifyResults` for each
function that was found in the input and analyzed.

Reviewed By: ymandel, sgatev

Differential Revision: https://reviews.llvm.org/D140859




More information about the All-commits mailing list