]> gcc.gnu.org Git - gcc.git/commit
ubsan: Fix ICE due to -fsanitize=object-size [PR105093]
authorJakub Jelinek <jakub@redhat.com>
Wed, 30 Mar 2022 08:49:47 +0000 (10:49 +0200)
committerJakub Jelinek <jakub@redhat.com>
Tue, 10 May 2022 08:14:35 +0000 (10:14 +0200)
commit2197da65c938e5f5dd7feb6c4c9be02f0b981275
tree0e8dd33553d8156ac613372faea00a7ffb146a76
parent8ea0c916cbb150c9a121eac95f2950d9bcea0b3e
ubsan: Fix ICE due to -fsanitize=object-size [PR105093]

The following testcase ICEs, because for a volatile X & RESULT_DECL
ubsan wants to take address of that reference.  instrument_object_size
is called with x, so the base is equal to the access and the var
is automatic, so there is no risk of an out of bounds access for it.
Normally we wouldn't instrument those because we fold address of the
t - address of inner to 0, add constant size of the decl and it is
equal to what __builtin_object_size computes.  But the volatile
results in the subtraction not being folded.

The first hunk fixes it by punting if we access the whole automatic
decl, so that even volatile won't cause a problem.
The second hunk (not strictly needed for this testcase) is similar
to what has been added to asan.cc recently, if we actually take
address of a decl and keep it in the IL, we better mark it addressable.

2022-03-30  Jakub Jelinek  <jakub@redhat.com>

PR sanitizer/105093
* ubsan.c (instrument_object_size): If t is equal to inner and
is a decl other than global var, punt.  When emitting call to
UBSAN_OBJECT_SIZE ifn, make sure base is addressable.

* g++.dg/ubsan/pr105093.C: New test.

(cherry picked from commit e3e68fa59ead502c24950298b53c637bbe535a74)
gcc/testsuite/g++.dg/ubsan/pr105093.C [new file with mode: 0644]
gcc/ubsan.c
This page took 0.065662 seconds and 6 git commands to generate.