[all-commits] [llvm/llvm-project] aceb34: [analyzer][NFC] Simplifications in ArrayBoundV2 (#...

DonatNagyE via All-commits all-commits at lists.llvm.org
Tue Oct 24 01:44:27 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: aceb34c7046d315d615feaa94a5941db13299a1b
      https://github.com/llvm/llvm-project/commit/aceb34c7046d315d615feaa94a5941db13299a1b
  Author: DonatNagyE <donat.nagy at ericsson.com>
  Date:   2023-10-24 (Tue, 24 Oct 2023)

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

  Log Message:
  -----------
  [analyzer][NFC] Simplifications in ArrayBoundV2 (#67572)

I'm planning to improve diagnostics generation in `ArrayBoundCheckerV2`
but before that I'm refactoring the source code to clean up some
over-complicated code and an inaccurate comment.

Changes in this commit:
- Remove the `mutable std::unique_ptr<BugType>` boilerplate, because
it's no longer needed.
- Remove the code duplication between the methods `reportOOB()` and
`reportTaintedOOB()`.
- Eliminate the class `RegionRawOffsetV2` because it's just a "reinvent
the wheel" version of `std::pair` and it was used only once, as a
temporary object that was immediately decomposed. (I suspect that
`RegionRawOffset` in MemRegion.cpp could also be eliminated.)
- Flatten the code of `computeOffset()` which had contained six nested
indentation levels before this commit.
- Ensure that `computeOffset()` returns `std::nullopt` instead of a
`{Region, <zero array index>}` pair in the case when it encounters a
`Location` that is not an `ElementRegion`. This ensures that the
`checkLocation` callback returns early when it handles a memory access
where it has "nothing to do" (no subscript operation or equivalent
pointer arithmetic). Note that this is still NFC because zero is a
valid index everywhere, so the old logic without this shortcut
eventually reached the same conclusion.
- Correct a wrong explanation comment in `getSimplifiedOffsets()`.




More information about the All-commits mailing list