[all-commits] [llvm/llvm-project] d448fc: [analyzer][NFC] Introduce CallDescriptionSets

Balazs Benics via All-commits all-commits at lists.llvm.org
Fri Nov 19 09:32:56 PST 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: d448fcd9b2238377dd8832ce9e35a37b59ef5aeb
      https://github.com/llvm/llvm-project/commit/d448fcd9b2238377dd8832ce9e35a37b59ef5aeb
  Author: Balazs Benics <balazs.benics at sigmatechnology.se>
  Date:   2021-11-19 (Fri, 19 Nov 2021)

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

  Log Message:
  -----------
  [analyzer][NFC] Introduce CallDescriptionSets

Sometimes we only want to decide if some function is called, and we
don't care which of the set.
This `CallDescriptionSet` will have the same behavior, except
instead of `lookup()` returning a pointer to the mapped value,
the `contains()` returns `bool`.
Internally, it uses the `CallDescriptionMap<bool>` for implementing the
behavior. It is preferred, to reuse the generic
`CallDescriptionMap::lookup()` logic, instead of duplicating it.
The generic version might be improved by implementing a hash lookup or
something along those lines.

Reviewed By: martong, Szelethus

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


  Commit: 6c512703a9e6e495afa0f44528821c27f28db795
      https://github.com/llvm/llvm-project/commit/6c512703a9e6e495afa0f44528821c27f28db795
  Author: Balazs Benics <balazs.benics at sigmatechnology.se>
  Date:   2021-11-19 (Fri, 19 Nov 2021)

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

  Log Message:
  -----------
  [analyzer][NFC] Introduce CallDescription::matches() in addition to isCalled()

This patch introduces `CallDescription::matches()` member function,
accepting a `CallEvent`.
Semantically, `Call.isCalled(CD)` is the same as `CD.matches(Call)`.

The patch also introduces the `matchesAny()` variadic free function template.
It accepts a `CallEvent` and at least one `CallDescription` to match
against.

Reviewed By: martong

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


  Commit: f18da190b0dba817d33ccd7727537f12304d8125
      https://github.com/llvm/llvm-project/commit/f18da190b0dba817d33ccd7727537f12304d8125
  Author: Balazs Benics <balazs.benics at sigmatechnology.se>
  Date:   2021-11-19 (Fri, 19 Nov 2021)

  Changed paths:
    M clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
    M clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp
    M clang/lib/StaticAnalyzer/Checkers/BlockInCriticalSectionChecker.cpp
    M clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
    M clang/lib/StaticAnalyzer/Checkers/ChrootChecker.cpp
    M clang/lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp
    M clang/lib/StaticAnalyzer/Checkers/MIGChecker.cpp
    M clang/lib/StaticAnalyzer/Checkers/MmapWriteExecChecker.cpp
    M clang/lib/StaticAnalyzer/Checkers/SimpleStreamChecker.cpp
    M clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
    M clang/lib/StaticAnalyzer/Checkers/StringChecker.cpp
    M clang/lib/StaticAnalyzer/Checkers/ValistChecker.cpp
    M clang/lib/StaticAnalyzer/Checkers/cert/PutenvWithAutoChecker.cpp
    M clang/lib/StaticAnalyzer/Core/CallEvent.cpp
    M clang/unittests/StaticAnalyzer/ConflictingEvalCallsTest.cpp
    M clang/unittests/StaticAnalyzer/NoStateChangeFuncVisitorTest.cpp

  Log Message:
  -----------
  [analyzer][NFC] Switch to using CallDescription::matches() instead of isCalled()

This patch replaces each use of the previous API with the new one.
In variadic cases, it will use the ADL `matchesAny(Call, CDs...)`
variadic function.
Also simplifies some code involving such operations.

Reviewed By: martong, xazax.hun

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


  Commit: 9ad0a90baa8ca8067fe65086056fffd083c86796
      https://github.com/llvm/llvm-project/commit/9ad0a90baa8ca8067fe65086056fffd083c86796
  Author: Balazs Benics <balazs.benics at sigmatechnology.se>
  Date:   2021-11-19 (Fri, 19 Nov 2021)

  Changed paths:
    M clang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp

  Log Message:
  -----------
  [analyzer][NFC] Demonstrate the use of CallDescriptionSet

Reviewed By: martong, xazax.hun

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


  Commit: de9d7e42aca29920e9918ecaed4ad9c45fa673f1
      https://github.com/llvm/llvm-project/commit/de9d7e42aca29920e9918ecaed4ad9c45fa673f1
  Author: Balazs Benics <balazs.benics at sigmatechnology.se>
  Date:   2021-11-19 (Fri, 19 Nov 2021)

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

  Log Message:
  -----------
  [analyzer][NFC] CallDescription should own the qualified name parts

Previously, CallDescription simply referred to the qualified name parts
by `const char*` pointers.
In the future we might want to dynamically load and populate
`CallDescriptionMaps`, hence we will need the `CallDescriptions` to
actually **own** their qualified name parts.

Reviewed By: martong, xazax.hun

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


  Commit: 97f1bf15b154ef32608fe17b82f2f312401d150c
      https://github.com/llvm/llvm-project/commit/97f1bf15b154ef32608fe17b82f2f312401d150c
  Author: Balazs Benics <balazs.benics at sigmatechnology.se>
  Date:   2021-11-19 (Fri, 19 Nov 2021)

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

  Log Message:
  -----------
  [analyzer][NFC] Consolidate the inner representation of CallDescriptions

`CallDescriptions` have a `RequiredArgs` and `RequiredParams` members,
but they are of different types, `unsigned` and `size_t` respectively.
In the patch I use only `unsigned` for both, that should be large enough
anyway.
I also introduce the `MaybeUInt` type alias for `Optional<unsigned>`.

Additionally, I also avoid the use of the //smart// less-than operator.

  template <typename T>
  constexpr bool operator<=(const Optional<T> &X, const T &Y);

Which would check if the optional **has** a value and compare the data
only after. I found it surprising, thus I think we are better off
without it.

Reviewed By: martong, xazax.hun

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


  Commit: e6ef134f3c77005438f9fb7c1d17d3c30747844e
      https://github.com/llvm/llvm-project/commit/e6ef134f3c77005438f9fb7c1d17d3c30747844e
  Author: Balazs Benics <balazs.benics at sigmatechnology.se>
  Date:   2021-11-19 (Fri, 19 Nov 2021)

  Changed paths:
    M clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallDescription.h
    M clang/lib/StaticAnalyzer/Checkers/ContainerModeling.cpp
    M clang/lib/StaticAnalyzer/Checkers/DebugContainerModeling.cpp
    M clang/lib/StaticAnalyzer/Checkers/DebugIteratorModeling.cpp
    M clang/lib/StaticAnalyzer/Core/CallDescription.cpp

  Log Message:
  -----------
  [analyzer][NFC] Use enum for CallDescription flags

Yeah, let's prefer a slightly stronger type representing this.

Reviewed By: martong, xazax.hun

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


Compare: https://github.com/llvm/llvm-project/compare/76effb001d33...e6ef134f3c77


More information about the All-commits mailing list