This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/61240] [4.8/4.9/4.10 Regression] Incorrect warning "integer overflow in expression" on pointer-pointer subtraction
- From: "rguenth at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 20 May 2014 08:38:19 +0000
- Subject: [Bug c/61240] [4.8/4.9/4.10 Regression] Incorrect warning "integer overflow in expression" on pointer-pointer subtraction
- Auto-submitted: auto-generated
- References: <bug-61240-4 at http dot gcc dot gnu dot org/bugzilla/>
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 0x7ffff6d54e28 type <integer_type 0x7ffff6c407e0 long int>
constant public overflow 1>
via c-common.c:overflow_warning called from
#1 0x000000000065b80e 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 0x000000000068f5ed in c_parser_binary_expression (parser=0x7ffff6d67000,
after=0x0, omp_atomic_lhs=<tree 0x0>)
at /space/rguenther/src/svn/trunk/gcc/c/c-parser.c:6282
#3 0x000000000068dfee in c_parser_conditional_expression (
parser=0x7ffff6d67000, after=0x0, omp_atomic_lhs=<tree 0x0>)
at /space/rguenther/src/svn/trunk/gcc/c/c-parser.c:5934
#4 0x000000000068dd75 in c_parser_expr_no_commas (parser=0x7ffff6d67000,
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.