This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]