This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Fix ubsan in gimple-fold.c (PR tree-optimization/82491).
- From: Martin Liška <mliska at suse dot cz>
- To: gcc-patches at gcc dot gnu dot org
- Cc: Richard Biener <richard dot guenther at gmail dot com>, Richard Sandiford <richard dot sandiford at arm dot com>
- Date: Mon, 19 Feb 2018 13:38:17 +0100
- Subject: [PATCH] Fix ubsan in gimple-fold.c (PR tree-optimization/82491).
- Authentication-results: sourceware.org; auth=none
Hi.
The patch was suggested by Richard Biener and then Richard Sandiford helped me to
rewrite it using poly-int. It prevents ubsan in gimple-fold.
Patch can bootstrap on ppc64le-redhat-linux and survives regression tests.
And it does not trigger ubsan in the test-case in gimple-fold.c.
Ready to be installed?
Martin
gcc/ChangeLog:
2018-02-19 Martin Liska <mliska@suse.cz>
Richard Sandiford <richard.sandiford@linaro.org>
PR tree-optimization/82491
* gimple-fold.c (get_base_constructor): Make earlier bail out
to prevent ubsan.
---
gcc/gimple-fold.c | 10 +++-------
1 file changed, 3 insertions(+), 7 deletions(-)
diff --git a/gcc/gimple-fold.c b/gcc/gimple-fold.c
index e556f050e43..c9dad6f42d1 100644
--- a/gcc/gimple-fold.c
+++ b/gcc/gimple-fold.c
@@ -6442,13 +6442,9 @@ get_base_constructor (tree base, poly_int64_pod *bit_offset,
if (TREE_CODE (base) == MEM_REF)
{
- if (!integer_zerop (TREE_OPERAND (base, 1)))
- {
- if (!tree_fits_shwi_p (TREE_OPERAND (base, 1)))
- return NULL_TREE;
- *bit_offset += (mem_ref_offset (base).force_shwi ()
- * BITS_PER_UNIT);
- }
+ poly_offset_int boff = *bit_offset + mem_ref_offset (base) * BITS_PER_UNIT;
+ if (!boff.to_shwi (bit_offset))
+ return NULL_TREE;
if (valueize
&& TREE_CODE (TREE_OPERAND (base, 0)) == SSA_NAME)