]> gcc.gnu.org Git - gcc.git/commit
tree-optimization/99824 - avoid excessive integer type precision in VN
authorRichard Biener <rguenther@suse.de>
Tue, 30 Mar 2021 09:22:52 +0000 (11:22 +0200)
committerRichard Biener <rguenther@suse.de>
Tue, 30 Mar 2021 12:00:58 +0000 (14:00 +0200)
commitbd3d919b58466a9837e423c1255b88215f89bc9d
tree486aa79830ac230854d7abba2a954efa4849f907
parent48c79f054bf435051c95ee093c45a0f8c9de5b4e
tree-optimization/99824 - avoid excessive integer type precision in VN

VN sometimes builds new integer types to handle accesss where precision
of the access type does not match the access size.  The way
ao_ref_init_from_vn_reference is computing the access size ignores
the access type in case the ref operands have an outermost
COMPONENT_REF which, in case it is an array for example, can be
way larger than the access size.  This can cause us to try
building an integer type with precision larger than WIDE_INT_MAX_PRECISION
eventually leading to memory corruption.

The following adjusts ao_ref_init_from_vn_reference to only lower
access sizes via the outermost COMPONENT_REF but otherwise honor
the access size as specified by the access type.

It also places an assert in integer type building that we remain
in the limits of WIDE_INT_MAX_PRECISION.  I chose the shared code
where we set TYPE_MIN/MAX_VALUE because that will immediately
cross the wide_ints capacity otherwise.

2021-03-30  Richard Biener  <rguenther@suse.de>

PR tree-optimization/99824
* stor-layout.c (set_min_and_max_values_for_integral_type):
Assert the precision is within the bounds of
WIDE_INT_MAX_PRECISION.
* tree-ssa-sccvn.c (ao_ref_init_from_vn_reference): Use
the outermost component ref only to lower the access size
and initialize that from the access type.

* gcc.dg/torture/pr99824.c: New testcase.
gcc/stor-layout.c
gcc/testsuite/gcc.dg/torture/pr99824.c [new file with mode: 0644]
gcc/tree-ssa-sccvn.c
This page took 0.062749 seconds and 5 git commands to generate.