The following completes the fix for PR67921 now that we have a testcase
for the non-pointer case.

Bootstrapped and tested on x86_64-unknown-linux-gnu, applied.

Richard.

2016-05-06  Richard Biener  <rguent...@suse.de>

        PR middle-end/70941
        * fold-const.c (split_tree): Always convert to the original type
        before negating.

        * gcc.dg/torture/pr70941.c: New testcase.

Index: gcc/fold-const.c
===================================================================
*** gcc/fold-const.c    (revision 235942)
--- gcc/fold-const.c    (working copy)
*************** split_tree (location_t loc, tree in, tre
*** 836,846 ****
        *minus_litp = *litp, *litp = 0;
        if (neg_conp_p)
        *conp = negate_expr (*conp);
!       if (neg_var_p)
        {
!         /* Convert to TYPE before negating a pointer type expr.  */
!         if (var && POINTER_TYPE_P (TREE_TYPE (var)))
!           var = fold_convert_loc (loc, type, var);
          var = negate_expr (var);
        }
      }
--- 836,845 ----
        *minus_litp = *litp, *litp = 0;
        if (neg_conp_p)
        *conp = negate_expr (*conp);
!       if (neg_var_p && var)
        {
!         /* Convert to TYPE before negating.  */
!         var = fold_convert_loc (loc, type, var);
          var = negate_expr (var);
        }
      }
*************** split_tree (location_t loc, tree in, tre
*** 863,872 ****
        else if (*minus_litp)
        *litp = *minus_litp, *minus_litp = 0;
        *conp = negate_expr (*conp);
!       /* Convert to TYPE before negating a pointer type expr.  */
!       if (var && POINTER_TYPE_P (TREE_TYPE (var)))
!       var = fold_convert_loc (loc, type, var);
!       var = negate_expr (var);
      }
  
    return var;
--- 862,873 ----
        else if (*minus_litp)
        *litp = *minus_litp, *minus_litp = 0;
        *conp = negate_expr (*conp);
!       if (var)
!       {
!         /* Convert to TYPE before negating.  */
!         var = fold_convert_loc (loc, type, var);
!         var = negate_expr (var);
!       }
      }
  
    return var;
Index: gcc/testsuite/gcc.dg/torture/pr70941.c
===================================================================
*** gcc/testsuite/gcc.dg/torture/pr70941.c      (revision 0)
--- gcc/testsuite/gcc.dg/torture/pr70941.c      (revision 0)
***************
*** 0 ****
--- 1,14 ----
+ /* { dg-do run } */
+ /* { dg-require-effective-target int32plus } */
+ 
+ extern void abort (void);
+ 
+ char a = 0, b = 0, c = 0, d = 0;
+ 
+ int main()
+ {
+   a = -(b - 405418259) - ((d && c) ^ 2040097152);
+   if (a != -109)
+     abort();
+   return 0;
+ }

Reply via email to