This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Fix PR81705
- From: Richard Biener <rguenther at suse dot de>
- To: gcc-patches at gcc dot gnu dot org
- Date: Fri, 4 Aug 2017 12:32:20 +0200 (CEST)
- Subject: [PATCH] Fix PR81705
- Authentication-results: sourceware.org; auth=none
The following fixes PR81705, a simple omission in my last association
patch.
Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk.
Richard.
2017-08-04 Richard Biener <rguenther@suse.de>
PR middle-end/81705
* fold-const.c (fold_binary_loc): Properly restrict
minus_var0 && minus_var1 case when associating undefined overflow
entities.
* c-c++-common/ubsan/pr81705.c: New testcase.
Index: gcc/fold-const.c
===================================================================
--- gcc/fold-const.c (revision 250865)
+++ gcc/fold-const.c (working copy)
@@ -9592,12 +9592,13 @@ fold_binary_loc (location_t loc,
if (POINTER_TYPE_P (atype)
|| (INTEGRAL_TYPE_P (atype) && !TYPE_OVERFLOW_WRAPS (atype)))
{
- if (var0 && var1)
+ if ((var0 && var1) || (minus_var0 && minus_var1))
{
/* ??? If split_tree would handle NEGATE_EXPR we could
- simplify this down to the var0/minus_var1 cases. */
- tree tmp0 = var0;
- tree tmp1 = var1;
+ simply reject these cases and the allowed cases would
+ be the var0/minus_var1 ones. */
+ tree tmp0 = var0 ? var0 : minus_var0;
+ tree tmp1 = var1 ? var1 : minus_var1;
bool one_neg = false;
if (TREE_CODE (tmp0) == NEGATE_EXPR)
Index: gcc/testsuite/c-c++-common/ubsan/pr81705.c
===================================================================
--- gcc/testsuite/c-c++-common/ubsan/pr81705.c (nonexistent)
+++ gcc/testsuite/c-c++-common/ubsan/pr81705.c (working copy)
@@ -0,0 +1,12 @@
+/* { dg-do run } */
+/* { dg-options "-fsanitize=undefined -fsanitize-undefined-trap-on-error" } */
+
+int var_4 = -1716607962;
+int var_14 = 943738830;
+volatile int a;
+int main()
+{
+ // (-(-1716607962) - 516151698) - -(9403738830)
+ a = (-var_4 - 516151698) - -var_14;
+ return 0;
+}