aboutsummaryrefslogtreecommitdiff
path: root/gcc/fold-const.c
diff options
context:
space:
mode:
authorRichard Biener <rguenther@suse.de>2017-06-14 11:40:20 +0000
committerRichard Biener <rguenth@gcc.gnu.org>2017-06-14 11:40:20 +0000
commit909263f855ae056b49b8fbbbcf594d7e9b90b434 (patch)
tree438e6ca62418d179e447ddb69fbd318488a45f11 /gcc/fold-const.c
parentc74985e3ee7f30091582908b1bdf3cdec5218897 (diff)
downloadgcc-909263f855ae056b49b8fbbbcf594d7e9b90b434.zip
gcc-909263f855ae056b49b8fbbbcf594d7e9b90b434.tar.gz
gcc-909263f855ae056b49b8fbbbcf594d7e9b90b434.tar.bz2
re PR middle-end/81088 (UBSAN: false positive as a result of reassosiation)
2017-06-14 Richard Biener <rguenther@suse.de> PR middle-end/81088 * fold-const.c (split_tree): Drop TREE_OVERFLOW flag from literal constants. (fold_binary_loc): When associating do not treat pre-existing TREE_OVERFLOW on literal constants as a reason to allow TREE_OVERFLOW on associated literal constants. * c-c++-common/ubsan/pr81088.c: New testcase. From-SVN: r249192
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r--gcc/fold-const.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 74bbdb0..8559b1d 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -880,6 +880,13 @@ split_tree (location_t loc, tree in, tree type, enum tree_code code,
}
}
+ if (*litp
+ && TREE_OVERFLOW_P (*litp))
+ *litp = drop_tree_overflow (*litp);
+ if (*minus_litp
+ && TREE_OVERFLOW_P (*minus_litp))
+ *minus_litp = drop_tree_overflow (*minus_litp);
+
return var;
}
@@ -9703,11 +9710,6 @@ fold_binary_loc (location_t loc,
+ (lit0 != 0) + (lit1 != 0)
+ (minus_lit0 != 0) + (minus_lit1 != 0))))
{
- bool any_overflows = false;
- if (lit0) any_overflows |= TREE_OVERFLOW (lit0);
- if (lit1) any_overflows |= TREE_OVERFLOW (lit1);
- if (minus_lit0) any_overflows |= TREE_OVERFLOW (minus_lit0);
- if (minus_lit1) any_overflows |= TREE_OVERFLOW (minus_lit1);
var0 = associate_trees (loc, var0, var1, code, atype);
con0 = associate_trees (loc, con0, con1, code, atype);
lit0 = associate_trees (loc, lit0, lit1, code, atype);
@@ -9738,9 +9740,8 @@ fold_binary_loc (location_t loc,
}
/* Don't introduce overflows through reassociation. */
- if (!any_overflows
- && ((lit0 && TREE_OVERFLOW_P (lit0))
- || (minus_lit0 && TREE_OVERFLOW_P (minus_lit0))))
+ if ((lit0 && TREE_OVERFLOW_P (lit0))
+ || (minus_lit0 && TREE_OVERFLOW_P (minus_lit0)))
return NULL_TREE;
if (minus_lit0)