From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1666) id 35E433838027; Mon, 9 May 2022 11:42:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 35E433838027 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Richard Biener To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-205] tree-optimization/105517 - avoid offset truncation during VN X-Act-Checkin: gcc X-Git-Author: Richard Biener X-Git-Refname: refs/heads/master X-Git-Oldrev: 93416de0cb72358b95a96fa4341b7b93a6805842 X-Git-Newrev: faabc751d0bb7e7fe86abfe8991b0307d585874a Message-Id: <20220509114258.35E433838027@sourceware.org> Date: Mon, 9 May 2022 11:42:58 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 09 May 2022 11:42:58 -0000 https://gcc.gnu.org/g:faabc751d0bb7e7fe86abfe8991b0307d585874a commit r13-205-gfaabc751d0bb7e7fe86abfe8991b0307d585874a Author: Richard Biener Date: Mon May 9 11:33:44 2022 +0200 tree-optimization/105517 - avoid offset truncation during VN When value-numbering an address expression like &p_74(D)->a1x[4294967295].a1; we are accumulating the byte offset in an 64bit integer. When later exploiting the duality between that and a POINTER_PLUS_EXPR we should avoid truncating that offset to fit in the target specific sizetype. While such overflows are generally undefined behavior, exploiting this may leads to spurious missing diagnostics. 2022-05-09 Richard Biener PR tree-optimization/105517 * tree-ssa-sccvn.cc (vn_reference_lookup): Make sure the accumulated offset can be represented in the POINTER_PLUS_EXPR IL. (vn_reference_insert): Likewise. * poly-int.h (sext_hwi): Add poly version of sext_hwi. Diff: --- gcc/poly-int.h | 13 +++++++++++++ gcc/tree-ssa-sccvn.cc | 14 ++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/gcc/poly-int.h b/gcc/poly-int.h index 2bf9d98599f..d085544a57e 100644 --- a/gcc/poly-int.h +++ b/gcc/poly-int.h @@ -1178,6 +1178,19 @@ lshift (const poly_int_pod &a, const Cb &b) } } +/* Poly version of sext_hwi, with the same interface. */ + +template +inline poly_int +sext_hwi (const poly_int &a, unsigned int precision) +{ + poly_int_pod r; + for (unsigned int i = 0; i < N; i++) + r.coeffs[i] = sext_hwi (a.coeffs[i], precision); + return r; +} + + /* Return true if a0 + a1 * x might equal b0 + b1 * x for some nonnegative integer x. */ diff --git a/gcc/tree-ssa-sccvn.cc b/gcc/tree-ssa-sccvn.cc index 76587632312..3732d06b0bb 100644 --- a/gcc/tree-ssa-sccvn.cc +++ b/gcc/tree-ssa-sccvn.cc @@ -3684,7 +3684,12 @@ vn_reference_lookup (tree op, tree vuse, vn_lookup_kind kind, break; off += vro->off; } - if (i == operands.length () - 1) + if (i == operands.length () - 1 + /* Make sure we the offset we accumulated in a 64bit int + fits the address computation carried out in target + offset precision. */ + && (off.coeffs[0] + == sext_hwi (off.coeffs[0], TYPE_PRECISION (sizetype)))) { gcc_assert (operands[i-1].opcode == MEM_REF); tree ops[2]; @@ -3808,7 +3813,12 @@ vn_reference_insert (tree op, tree result, tree vuse, tree vdef) break; off += vro->off; } - if (i == operands.length () - 1) + if (i == operands.length () - 1 + /* Make sure we the offset we accumulated in a 64bit int + fits the address computation carried out in target + offset precision. */ + && (off.coeffs[0] + == sext_hwi (off.coeffs[0], TYPE_PRECISION (sizetype)))) { gcc_assert (operands[i-1].opcode == MEM_REF); tree ops[2];