[Bug c/61240] [4.8/4.9/4.10 Regression] Incorrect warning integer overflow in expression on pointer-pointer subtraction

2014-08-04 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61240

Marek Polacek mpolacek at gcc dot gnu.org changed:

   What|Removed |Added

 Status|NEW |ASSIGNED
   Assignee|unassigned at gcc dot gnu.org  |mpolacek at gcc dot 
gnu.org

--- Comment #5 from Marek Polacek mpolacek at gcc dot gnu.org ---
Maybe best would be to remove the optimization in pointer_diff altogether. 
Mine for now.


[Bug c/61240] [4.8/4.9/4.10 Regression] Incorrect warning integer overflow in expression on pointer-pointer subtraction

2014-08-04 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61240

--- Comment #6 from Jakub Jelinek jakub at gcc dot gnu.org ---
But in that case we should have an adequate replacement on the
match_and_simplify side.


[Bug c/61240] [4.8/4.9/4.10 Regression] Incorrect warning integer overflow in expression on pointer-pointer subtraction

2014-08-04 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61240

--- Comment #7 from Marek Polacek mpolacek at gcc dot gnu.org ---
But C++ has its own pointer_diff version that doesn't do such optimization. 
With my change the C FE would generate the same expr as the C++ FE.  And FEs
shouldn't perform such optimizations anyway.


[Bug c/61240] [4.8/4.9/4.10 Regression] Incorrect warning integer overflow in expression on pointer-pointer subtraction

2014-07-01 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61240

Jakub Jelinek jakub at gcc dot gnu.org changed:

   What|Removed |Added

 CC||jakub at gcc dot gnu.org

--- Comment #4 from Jakub Jelinek jakub at gcc dot gnu.org ---
Started with r184965.


[Bug c/61240] [4.8/4.9/4.10 Regression] Incorrect warning integer overflow in expression on pointer-pointer subtraction

2014-06-25 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61240

Marek Polacek mpolacek at gcc dot gnu.org changed:

   What|Removed |Added

 CC||mpolacek at gcc dot gnu.org

--- Comment #3 from Marek Polacek mpolacek at gcc dot gnu.org ---
Richi, did you mean something like this?  With this we wouldn't warn on nor p -
(p - 1); neither q - (q - 1); line...

--- a/gcc/c/c-typeck.c
+++ b/gcc/c/c-typeck.c
@@ -3513,6 +3513,9 @@ pointer_diff (location_t loc, tree op0, tree op1)
 {
   lit0 = TREE_OPERAND (con0, 1);
   con0 = TREE_OPERAND (con0, 0);
+  lit0 = convert (inttype, lit0);
+  if (TREE_CODE (lit0) == INTEGER_CST)
+   TREE_OVERFLOW (lit0) = 0;
 }
   else
 lit0 = integer_zero_node;
@@ -3521,6 +3524,9 @@ pointer_diff (location_t loc, tree op0, tree op1)
 {
   lit1 = TREE_OPERAND (con1, 1);
   con1 = TREE_OPERAND (con1, 0);
+  lit1 = convert (inttype, lit1);
+  if (TREE_CODE (lit1) == INTEGER_CST)
+   TREE_OVERFLOW (lit1) = 0;
 }
   else
 lit1 = integer_zero_node;


[Bug c/61240] [4.8/4.9/4.10 Regression] Incorrect warning integer overflow in expression on pointer-pointer subtraction

2014-05-22 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61240

Richard Biener rguenth at gcc dot gnu.org changed:

   What|Removed |Added

   Target Milestone|4.8.3   |4.8.4

--- Comment #2 from Richard Biener rguenth at gcc dot gnu.org ---
GCC 4.8.3 is being released, adjusting target milestone.


[Bug c/61240] [4.8/4.9/4.10 Regression] Incorrect warning integer overflow in expression on pointer-pointer subtraction

2014-05-20 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61240

Richard Biener rguenth at gcc dot gnu.org changed:

   What|Removed |Added

 Status|UNCONFIRMED |NEW
   Last reconfirmed||2014-05-20
   Target Milestone|--- |4.8.3
Summary|Incorrect warning integer  |[4.8/4.9/4.10 Regression]
   |overflow in expression on  |Incorrect warning integer
   |pointer-pointer subtraction |overflow in expression on
   ||pointer-pointer subtraction
 Ever confirmed|0   |1

--- Comment #1 from Richard Biener rguenth at gcc dot gnu.org ---
We warn for

 integer_cst 0x76d54e28 type integer_type 0x76c407e0 long int
constant public overflow 1

via c-common.c:overflow_warning called from

#1  0x0065b80e in parser_build_binary_op (location=5653, 
code=MINUS_EXPR, arg1=..., arg2=...)
at /space/rguenther/src/svn/trunk/gcc/c/c-typeck.c:3411
#2  0x0068f5ed in c_parser_binary_expression (parser=0x76d67000, 
after=0x0, omp_atomic_lhs=tree 0x0)
at /space/rguenther/src/svn/trunk/gcc/c/c-parser.c:6282
#3  0x0068dfee in c_parser_conditional_expression (
parser=0x76d67000, after=0x0, omp_atomic_lhs=tree 0x0)
at /space/rguenther/src/svn/trunk/gcc/c/c-parser.c:5934
#4  0x0068dd75 in c_parser_expr_no_commas (parser=0x76d67000, 
after=0x0, omp_atomic_lhs=tree 0x0)
at /space/rguenther/src/svn/trunk/gcc/c/c-parser.c:5852

when building p - (p + -1U) which gets simplified to - -1U - 1U (with overflow
set - as it's sizetype arithmetic).  pointer_diff is guilty here which calls

  /* First do the subtraction as integers;
 then drop through to build the divide operator.
 Do not do default conversions on the minus operator
 in case restype is a short type.  */

  op0 = build_binary_op (loc,
 MINUS_EXPR, convert (inttype, op0),
 convert (inttype, op1), 0);

doing 0 - -1U, converting them to inttype (long int) first.  I suggest
to do that conversion and strip overflow bits in the POINTER_PLUS_EXPR
decomposition part.