diff options
author | Jakub Jelinek <jakub@redhat.com> | 2020-12-31 10:20:39 +0100 |
---|---|---|
committer | Jakub Jelinek <jakub@redhat.com> | 2020-12-31 10:20:39 +0100 |
commit | a9ec9902d7f1a9bf7a2778c3fb8fc75bc2df2cef (patch) | |
tree | 35dfacac654745f872232ce25e0897db144a2793 /gcc/print-rtl-function.c | |
parent | d96b8556e569a1ccce36ef990e167031d07a661a (diff) | |
download | gcc-a9ec9902d7f1a9bf7a2778c3fb8fc75bc2df2cef.zip gcc-a9ec9902d7f1a9bf7a2778c3fb8fc75bc2df2cef.tar.gz gcc-a9ec9902d7f1a9bf7a2778c3fb8fc75bc2df2cef.tar.bz2 |
fold-const: Avoid (cast) ((cast2) x p+ y) folding for -fsanitize=alignment [PR98206]
The following testcase is diagnosed by UBSan as invalid, even when it is
valid.
We have a derived type Base2 at offset 1 with alignment 1 and do:
(const Derived &) ((const Base2 *) this + -1)
but the folder before ubsan in the FE gets a chance to instrument it
optimizes that into:
(const Derived &) this + -1
and so we require that this has 8-byte alignment which Derived class needs.
Fixed by avoiding such an optimization when -fsanitize=alignment is in
effect if it would affect the alignments (and guarded with !in_gimple_form
because we don't really care during GIMPLE, though pointer conversions are
useless then and so such folding isn't needed very much during GIMPLE).
2020-12-31 Jakub Jelinek <jakub@redhat.com>
PR c++/98206
* fold-const.c: Include asan.h.
(fold_unary_loc): Don't optimize (ptr_type) (((ptr_type2) x) p+ y)
into ((ptr_type) x) p+ y if sanitizing alignment in GENERIC and
ptr_type points to type with higher alignment than ptr_type2.
* g++.dg/ubsan/align-4.C: New test.
Diffstat (limited to 'gcc/print-rtl-function.c')
0 files changed, 0 insertions, 0 deletions