]> git.ipfire.org Git - thirdparty/gcc.git/commit
asan: Don't fold some strlens with -fsanitize=address [PR110676]
authorJakub Jelinek <jakub@redhat.com>
Tue, 6 Feb 2024 12:00:04 +0000 (13:00 +0100)
committerJakub Jelinek <jakub@redhat.com>
Tue, 6 Feb 2024 12:00:04 +0000 (13:00 +0100)
commitd3eac7d96de790df51859f63c13838f153b416de
tree318ce3be1d43be32257a529c4298739f133f2cf4
parent483c061d699309d58a1b28ce5c00ee9b55a7365c
asan: Don't fold some strlens with -fsanitize=address [PR110676]

The UB on the following testcase isn't diagnosed by -fsanitize=address,
because we see that the array has a single element and optimize the
strlen to 0.  I think it is fine to assume e.g. for range purposes the
lower bound for the strlen as long as we don't try to optimize
strlen (str)
where we know that it returns [26, 42] to
26 + strlen (str + 26), but for the upper bound we really want to punt
on optimizing that for -fsanitize=address to read all the bytes of the
string and diagnose if we run to object end etc.

2024-02-06  Jakub Jelinek  <jakub@redhat.com>

PR sanitizer/110676
* gimple-fold.cc (gimple_fold_builtin_strlen): For -fsanitize=address
reset maxlen to sizetype maximum.

* gcc.dg/asan/pr110676.c: New test.
gcc/gimple-fold.cc
gcc/testsuite/gcc.dg/asan/pr110676.c [new file with mode: 0644]