Changes

Summary

  1. [analyzer][NFC] Introduce CallDescriptionSets (details)
  2. [analyzer][NFC] Introduce CallDescription::matches() in addition to isCalled() (details)
  3. [analyzer][NFC] Switch to using CallDescription::matches() instead of isCalled() (details)
  4. [analyzer][NFC] Demonstrate the use of CallDescriptionSet (details)
  5. [analyzer][NFC] CallDescription should own the qualified name parts (details)
  6. [analyzer][NFC] Consolidate the inner representation of CallDescriptions (details)
  7. [analyzer][NFC] Use enum for CallDescription flags (details)
  8. [analyzer][NFC] MaybeUInt -> MaybeCount (details)
  9. [DSE] Improve handling of `strncpy` in Dead Store Elimination (details)
Commit d448fcd9b2238377dd8832ce9e35a37b59ef5aeb by balazs.benics
[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
The file was modifiedclang/lib/StaticAnalyzer/Core/CallDescription.cpp
The file was modifiedclang/include/clang/StaticAnalyzer/Core/PathSensitive/CallDescription.h
Commit 6c512703a9e6e495afa0f44528821c27f28db795 by balazs.benics
[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
The file was modifiedclang/include/clang/StaticAnalyzer/Core/PathSensitive/CallDescription.h
The file was modifiedclang/lib/StaticAnalyzer/Core/CallDescription.cpp
The file was modifiedclang/lib/StaticAnalyzer/Core/CallEvent.cpp
Commit f18da190b0dba817d33ccd7727537f12304d8125 by balazs.benics
[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
The file was modifiedclang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
The file was modifiedclang/lib/StaticAnalyzer/Checkers/ValistChecker.cpp
The file was modifiedclang/unittests/StaticAnalyzer/ConflictingEvalCallsTest.cpp
The file was modifiedclang/lib/StaticAnalyzer/Checkers/BlockInCriticalSectionChecker.cpp
The file was modifiedclang/lib/StaticAnalyzer/Checkers/cert/PutenvWithAutoChecker.cpp
The file was modifiedclang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
The file was modifiedclang/lib/StaticAnalyzer/Core/CallEvent.cpp
The file was modifiedclang/lib/StaticAnalyzer/Checkers/MIGChecker.cpp
The file was modifiedclang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
The file was modifiedclang/unittests/StaticAnalyzer/NoStateChangeFuncVisitorTest.cpp
The file was modifiedclang/lib/StaticAnalyzer/Checkers/StringChecker.cpp
The file was modifiedclang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp
The file was modifiedclang/lib/StaticAnalyzer/Checkers/ChrootChecker.cpp
The file was modifiedclang/lib/StaticAnalyzer/Checkers/MmapWriteExecChecker.cpp
The file was modifiedclang/lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp
The file was modifiedclang/lib/StaticAnalyzer/Checkers/SimpleStreamChecker.cpp
Commit 9ad0a90baa8ca8067fe65086056fffd083c86796 by balazs.benics
[analyzer][NFC] Demonstrate the use of CallDescriptionSet

Reviewed By: martong, xazax.hun

Differential Revision: https://reviews.llvm.org/D113592
The file was modifiedclang/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp
Commit de9d7e42aca29920e9918ecaed4ad9c45fa673f1 by balazs.benics
[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
The file was modifiedclang/lib/StaticAnalyzer/Core/CallDescription.cpp
The file was modifiedclang/include/clang/StaticAnalyzer/Core/PathSensitive/CallDescription.h
Commit 97f1bf15b154ef32608fe17b82f2f312401d150c by balazs.benics
[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
The file was modifiedclang/include/clang/StaticAnalyzer/Core/PathSensitive/CallDescription.h
The file was modifiedclang/lib/StaticAnalyzer/Core/CallDescription.cpp
Commit e6ef134f3c77005438f9fb7c1d17d3c30747844e by balazs.benics
[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
The file was modifiedclang/lib/StaticAnalyzer/Checkers/DebugContainerModeling.cpp
The file was modifiedclang/lib/StaticAnalyzer/Checkers/ContainerModeling.cpp
The file was modifiedclang/include/clang/StaticAnalyzer/Core/PathSensitive/CallDescription.h
The file was modifiedclang/lib/StaticAnalyzer/Core/CallDescription.cpp
The file was modifiedclang/lib/StaticAnalyzer/Checkers/DebugIteratorModeling.cpp
Commit d5de568cc7375281b14bd2632576bff7f4afabc3 by balazs.benics
[analyzer][NFC] MaybeUInt -> MaybeCount

I forgot to include this in D113594

Differential Revision: https://reviews.llvm.org/D113594
The file was modifiedclang/include/clang/StaticAnalyzer/Core/PathSensitive/CallDescription.h
The file was modifiedclang/lib/StaticAnalyzer/Core/CallDescription.cpp
Commit 7eec832def5717b1bddb72c3b99c3df4f7a2f6da by flo
[DSE] Improve handling of `strncpy` in Dead Store Elimination

Fixes PR#52062 and one of the remaining cases of PR#47644.

Reviewed By: fhahn

Differential Revision: https://reviews.llvm.org/D114035
The file was modifiedllvm/test/Transforms/DeadStoreElimination/libcalls.ll
The file was modifiedllvm/lib/Transforms/Scalar/DeadStoreElimination.cpp