[all-commits] [llvm/llvm-project] 5644d1: [analyzer][NFC] Add unittests for CallDescription ...

Balazs Benics via All-commits all-commits at lists.llvm.org
Mon Oct 18 05:58:18 PDT 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 5644d152578f4604f7dc8c908a0a3f91a726ad80
      https://github.com/llvm/llvm-project/commit/5644d152578f4604f7dc8c908a0a3f91a726ad80
  Author: Balazs Benics <balazs.benics at sigmatechnology.se>
  Date:   2021-10-18 (Mon, 18 Oct 2021)

  Changed paths:
    M clang/unittests/StaticAnalyzer/CallDescriptionTest.cpp

  Log Message:
  -----------
  [analyzer][NFC] Add unittests for CallDescription and split the old ones

This NFC change accomplishes three things:
1) Splits up the single unittest into reasonable segments.
2) Extends the test infra using a template to select the AST-node
   from which it is supposed to construct a `CallEvent`.
3) Adds a *lot* of different tests, documenting the current
   capabilities of the `CallDescription`. The corresponding tests are
   marked with `FIXME`s, where the current behavior should be different.

Both `CXXMemberCallExpr` and `CXXOperatorCallExpr` are derived from
`CallExpr`, so they are matched by using the default template parameter.
On the other hand, `CXXConstructExpr` is not derived from `CallExpr`.
In case we want to match for them, we need to pass the type explicitly
to the `CallDescriptionAction`.

About destructors:
They have no AST-node, but they are generated in the CFG machinery in
the analyzer. Thus, to be able to match against them, we would need to
construct a CFG and walk on that instead of simply walking the AST.

I'm also relaxing the `EXPECT`ation in the
`CallDescriptionConsumer::performTest()`, to check the `LookupResult`
only if we matched for the `CallDescription`.
This is necessary to allow tests in which we expect *no* matches at all.

Reviewed By: martong

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


  Commit: 3ec7b91141da4b3f4dce4964ca3ea7c3549584d2
      https://github.com/llvm/llvm-project/commit/3ec7b91141da4b3f4dce4964ca3ea7c3549584d2
  Author: Balazs Benics <balazs.benics at sigmatechnology.se>
  Date:   2021-10-18 (Mon, 18 Oct 2021)

  Changed paths:
    M clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
    M clang/lib/StaticAnalyzer/Core/CallEvent.cpp

  Log Message:
  -----------
  [analyzer][NFC] Refactor CallEvent::isCalled()

Refactor the code to make it more readable.

It will set up further changes, and improvements to this code in
subsequent patches.
This is a non-functional change.

Reviewed By: martong

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


  Commit: 72d04d7b2b53eea977e160551077cf1a3f51ba9a
      https://github.com/llvm/llvm-project/commit/72d04d7b2b53eea977e160551077cf1a3f51ba9a
  Author: Balazs Benics <balazs.benics at sigmatechnology.se>
  Date:   2021-10-18 (Mon, 18 Oct 2021)

  Changed paths:
    M clang/lib/StaticAnalyzer/Core/CallEvent.cpp
    M clang/unittests/StaticAnalyzer/CallDescriptionTest.cpp

  Log Message:
  -----------
  [analyzer] Allow matching non-CallExprs using CallDescriptions

Fallback to stringification and string comparison if we cannot compare
the `IdentifierInfo`s, which is the case for C++ overloaded operators,
constructors, destructors, etc.

Examples:
  { "std", "basic_string", "basic_string", 2} // match the 2 param std::string constructor
  { "std", "basic_string", "~basic_string" }  // match the std::string destructor
  { "aaa", "bbb", "operator int" } // matches the struct bbb conversion operator to int

Reviewed By: martong

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


Compare: https://github.com/llvm/llvm-project/compare/cbf778a592fa...72d04d7b2b53


More information about the All-commits mailing list