diff options
author | NagyDonat <donat.nagy@ericsson.com> | 2024-02-22 14:19:20 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-22 14:19:20 +0100 |
commit | fa8a21144ec9a6836e9bf1e3bf5cd0b2f058209e (patch) | |
tree | 8ca9f23939d83361fafc465aed34c333dccd4ae1 /llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | |
parent | b47f63d3c8fedf7c98b7f58e892e784fddee4601 (diff) | |
download | llvm-fa8a21144ec9a6836e9bf1e3bf5cd0b2f058209e.zip llvm-fa8a21144ec9a6836e9bf1e3bf5cd0b2f058209e.tar.gz llvm-fa8a21144ec9a6836e9bf1e3bf5cd0b2f058209e.tar.bz2 |
[analyzer] Improve handling of unsigned values in ArrayBoundCheckerV2 (#81034)
A memory access is an out of bounds error if the offset is < the extent
of the memory region. Notice that here "<" is a _mathematical_
comparison between two numbers and NOT a C/C++ operator that compares
two typed C++ values: for example -1 < 1000 is true in mathematics, but
if the `-1` is an `int` and the `1000` is a `size_t` value, then
evaluating the C/C++ operator `<` will return false because the `-1`
will be converted to `SIZE_MAX` by the automatic type conversions.
This means that it's incorrect to perform a bounds check with
`evalBinOpNN(State, BO_LT, ...)` which performs automatic conversions
and can produce wildly incorrect results.
ArrayBoundsCheckerV2 already had a special case where it avoided calling
`evalBinOpNN` in a situation where it would have performed an automatic
conversion; this commit replaces that code with a more general one that
covers more situations. (It's still not perfect, but it's better than
the previous version and I think it will cover practically all
real-world code.)
Note that this is not a limitation/bug of the simplification algorithm
defined in `getSimplifedOffsets()`: the simplification is not applied in
the test case `test_comparison_with_extent_symbol` (because the `Extent`
is not a concrete int), but without the new code it would still run into
a `-1 < UNSIGNED` comparison that evaluates to false because
`evalBinOpNN` performs an automatic type conversion.
Diffstat (limited to 'llvm/lib/Bitcode/Writer/BitcodeWriter.cpp')
0 files changed, 0 insertions, 0 deletions