diff options
author | Tim Lange <mail@tim-lange.me> | 2022-09-10 23:53:48 +0200 |
---|---|---|
committer | Tim Lange <mail@tim-lange.me> | 2022-09-11 23:55:20 +0200 |
commit | 0ea5e3f4542832b8da016b152695e64a2a386309 (patch) | |
tree | 37e285532e7f807019eae14d388dbbedbea5155c /gcc/analyzer/store.h | |
parent | 5b3496e2ea632463f4118928a87639454c87a859 (diff) | |
download | gcc-0ea5e3f4542832b8da016b152695e64a2a386309.zip gcc-0ea5e3f4542832b8da016b152695e64a2a386309.tar.gz gcc-0ea5e3f4542832b8da016b152695e64a2a386309.tar.bz2 |
analyzer: consider empty ranges and zero byte accesses [PR106845]
This patch adds handling of empty ranges in bit_range and byte_range and
adds an assertion to member functions that assume a positive size.
Further, the patch fixes an ICE caused by an empty byte_range passed to
byte_range::exceeds_p.
Regression-tested on Linux x86_64.
2022-09-10 Tim Lange <mail@tim-lange.me>
gcc/analyzer/ChangeLog:
PR analyzer/106845
* region-model.cc (region_model::check_region_bounds):
Bail out if 0 bytes were accessed.
* store.cc (byte_range::dump_to_pp):
Add special case for empty ranges.
(byte_range::exceeds_p): Restrict to non-empty ranges.
(byte_range::falls_short_of_p): Restrict to non-empty ranges.
* store.h (bit_range::empty_p): New function.
(bit_range::get_last_byte_offset): Restrict to non-empty ranges.
(byte_range::empty_p): New function.
(byte_range::get_last_byte_offset): Restrict to non-empty ranges.
gcc/testsuite/ChangeLog:
PR analyzer/106845
* gcc.dg/analyzer/out-of-bounds-zero.c: New test.
* gcc.dg/analyzer/pr106845.c: New test.
Diffstat (limited to 'gcc/analyzer/store.h')
-rw-r--r-- | gcc/analyzer/store.h | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/gcc/analyzer/store.h b/gcc/analyzer/store.h index ac8b685..d172ee7 100644 --- a/gcc/analyzer/store.h +++ b/gcc/analyzer/store.h @@ -237,6 +237,11 @@ struct bit_range void dump_to_pp (pretty_printer *pp) const; void dump () const; + bool empty_p () const + { + return m_size_in_bits == 0; + } + bit_offset_t get_start_bit_offset () const { return m_start_bit_offset; @@ -247,6 +252,7 @@ struct bit_range } bit_offset_t get_last_bit_offset () const { + gcc_assert (!empty_p ()); return get_next_bit_offset () - 1; } @@ -297,6 +303,11 @@ struct byte_range void dump_to_pp (pretty_printer *pp) const; void dump () const; + bool empty_p () const + { + return m_size_in_bytes == 0; + } + bool contains_p (byte_offset_t offset) const { return (offset >= get_start_byte_offset () @@ -329,6 +340,7 @@ struct byte_range } byte_offset_t get_last_byte_offset () const { + gcc_assert (!empty_p ()); return m_start_byte_offset + m_size_in_bytes - 1; } |