* [Bug middle-end/32628] [4.3 Regression] bogus integer overflow warning
2007-07-04 23:31 [Bug c/32628] New: bogus integer overflow warning ak at muc dot de
@ 2007-07-04 23:35 ` pinskia at gcc dot gnu dot org
2007-07-05 19:02 ` pinskia at gcc dot gnu dot org
` (10 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-07-04 23:35 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from pinskia at gcc dot gnu dot org 2007-07-04 23:34 -------
A simple example is:
void *f(void)
{
char *a = ((char*)0)+(unsigned long long)(-1);
return a;
}
This is caused by pointer_plus so mine.
--
pinskia at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
AssignedTo|unassigned at gcc dot gnu |pinskia at gcc dot gnu dot
|dot org |org
Status|UNCONFIRMED |ASSIGNED
Component|c |middle-end
Ever Confirmed|0 |1
Keywords| |diagnostic
Last reconfirmed|0000-00-00 00:00:00 |2007-07-04 23:34:35
date| |
Summary|bogus integer overflow |[4.3 Regression] bogus
|warning |integer overflow warning
Target Milestone|--- |4.3.0
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32628
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug middle-end/32628] [4.3 Regression] bogus integer overflow warning
2007-07-04 23:31 [Bug c/32628] New: bogus integer overflow warning ak at muc dot de
2007-07-04 23:35 ` [Bug middle-end/32628] [4.3 Regression] " pinskia at gcc dot gnu dot org
@ 2007-07-05 19:02 ` pinskia at gcc dot gnu dot org
2007-07-05 21:57 ` ebotcazou at gcc dot gnu dot org
` (9 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-07-05 19:02 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from pinskia at gcc dot gnu dot org 2007-07-05 19:02 -------
This patch works for me:
Index: fold-const.c
===================================================================
--- fold-const.c (revision 126338)
+++ fold-const.c (working copy)
@@ -282,14 +282,8 @@
HOST_WIDE_INT high, int overflowable,
bool overflowed)
{
- int sign_extended_type;
bool overflow;
- /* Size types *are* sign extended. */
- sign_extended_type = (!TYPE_UNSIGNED (type)
- || (TREE_CODE (type) == INTEGER_TYPE
- && TYPE_IS_SIZETYPE (type)));
-
overflow = fit_double_type (low, high, &low, &high, type);
/* If we need to set overflow flags, return a new unshared node. */
@@ -297,7 +291,7 @@
{
if (overflowed
|| overflowable < 0
- || (overflowable > 0 && sign_extended_type))
+ || (overflowable > 0 && !TYPE_UNSIGNED (type)))
{
tree t = make_node (INTEGER_CST);
TREE_INT_CST_LOW (t) = low;
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32628
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug middle-end/32628] [4.3 Regression] bogus integer overflow warning
2007-07-04 23:31 [Bug c/32628] New: bogus integer overflow warning ak at muc dot de
2007-07-04 23:35 ` [Bug middle-end/32628] [4.3 Regression] " pinskia at gcc dot gnu dot org
2007-07-05 19:02 ` pinskia at gcc dot gnu dot org
@ 2007-07-05 21:57 ` ebotcazou at gcc dot gnu dot org
2007-07-05 22:57 ` pinskia at gcc dot gnu dot org
` (8 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: ebotcazou at gcc dot gnu dot org @ 2007-07-05 21:57 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from ebotcazou at gcc dot gnu dot org 2007-07-05 21:57 -------
> This patch works for me:
Well, that sizetypes are sign-extended is assumed in other places too.
--
ebotcazou at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |ebotcazou at gcc dot gnu dot
| |org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32628
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug middle-end/32628] [4.3 Regression] bogus integer overflow warning
2007-07-04 23:31 [Bug c/32628] New: bogus integer overflow warning ak at muc dot de
` (2 preceding siblings ...)
2007-07-05 21:57 ` ebotcazou at gcc dot gnu dot org
@ 2007-07-05 22:57 ` pinskia at gcc dot gnu dot org
2007-07-06 0:34 ` pinskia at gcc dot gnu dot org
` (7 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-07-05 22:57 UTC (permalink / raw)
To: gcc-bugs
------- Comment #4 from pinskia at gcc dot gnu dot org 2007-07-05 22:57 -------
> Well, that sizetypes are sign-extended is assumed in other places too.
Yes this is known but this place is "special". Though I have not figured out
why we are setting overflow in general here anyways.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32628
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug middle-end/32628] [4.3 Regression] bogus integer overflow warning
2007-07-04 23:31 [Bug c/32628] New: bogus integer overflow warning ak at muc dot de
` (3 preceding siblings ...)
2007-07-05 22:57 ` pinskia at gcc dot gnu dot org
@ 2007-07-06 0:34 ` pinskia at gcc dot gnu dot org
2007-07-06 4:12 ` pinskia at gcc dot gnu dot org
` (6 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-07-06 0:34 UTC (permalink / raw)
To: gcc-bugs
------- Comment #5 from pinskia at gcc dot gnu dot org 2007-07-06 00:34 -------
Some more information, I don't think conversion should set the overflow bit any
more.
Roger started doing some of this work with:
http://gcc.gnu.org/ml/gcc-patches/2006-11/msg00812.html
But I don't know what happened after that as Roger disappeared.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32628
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug middle-end/32628] [4.3 Regression] bogus integer overflow warning
2007-07-04 23:31 [Bug c/32628] New: bogus integer overflow warning ak at muc dot de
` (4 preceding siblings ...)
2007-07-06 0:34 ` pinskia at gcc dot gnu dot org
@ 2007-07-06 4:12 ` pinskia at gcc dot gnu dot org
2007-07-18 15:22 ` pinskia at gcc dot gnu dot org
` (5 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-07-06 4:12 UTC (permalink / raw)
To: gcc-bugs
------- Comment #6 from pinskia at gcc dot gnu dot org 2007-07-06 04:12 -------
This patch is most likely better:
Index: fold-const.c
===================================================================
--- fold-const.c (revision 126396)
+++ fold-const.c (working copy)
@@ -2063,9 +2063,7 @@
appropriately sign-extended or truncated. */
t = force_fit_type_double (type, TREE_INT_CST_LOW (arg1),
TREE_INT_CST_HIGH (arg1),
- /* Don't set the overflow when
- converting a pointer */
- !POINTER_TYPE_P (TREE_TYPE (arg1)),
+ 0,
(TREE_INT_CST_HIGH (arg1) < 0
&& (TYPE_UNSIGNED (type)
< TYPE_UNSIGNED (TREE_TYPE (arg1))))
So don't set overflow for conversion.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32628
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug middle-end/32628] [4.3 Regression] bogus integer overflow warning
2007-07-04 23:31 [Bug c/32628] New: bogus integer overflow warning ak at muc dot de
` (5 preceding siblings ...)
2007-07-06 4:12 ` pinskia at gcc dot gnu dot org
@ 2007-07-18 15:22 ` pinskia at gcc dot gnu dot org
2007-08-10 0:39 ` mmitchel at gcc dot gnu dot org
` (4 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-07-18 15:22 UTC (permalink / raw)
To: gcc-bugs
------- Comment #7 from pinskia at gcc dot gnu dot org 2007-07-18 15:22 -------
>So don't set overflow for conversion.
When I tested this patch, it caused Ada not to bootstrap so I have to look more
into it.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32628
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug middle-end/32628] [4.3 Regression] bogus integer overflow warning
2007-07-04 23:31 [Bug c/32628] New: bogus integer overflow warning ak at muc dot de
` (6 preceding siblings ...)
2007-07-18 15:22 ` pinskia at gcc dot gnu dot org
@ 2007-08-10 0:39 ` mmitchel at gcc dot gnu dot org
2008-01-15 15:03 ` rguenth at gcc dot gnu dot org
` (3 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: mmitchel at gcc dot gnu dot org @ 2007-08-10 0:39 UTC (permalink / raw)
To: gcc-bugs
--
mmitchel at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Priority|P3 |P2
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32628
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug middle-end/32628] [4.3 Regression] bogus integer overflow warning
2007-07-04 23:31 [Bug c/32628] New: bogus integer overflow warning ak at muc dot de
` (7 preceding siblings ...)
2007-08-10 0:39 ` mmitchel at gcc dot gnu dot org
@ 2008-01-15 15:03 ` rguenth at gcc dot gnu dot org
2008-01-16 22:11 ` rguenth at gcc dot gnu dot org
` (2 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2008-01-15 15:03 UTC (permalink / raw)
To: gcc-bugs
------- Comment #8 from rguenth at gcc dot gnu dot org 2008-01-15 14:44 -------
Reduced testcase:
int f(char *device)
{
return device == ((char *)0 + ~0UL);
}
for building the POINTER_PLUS_EXPR we convert the unsigned offset to
sizetype which causes the double-int (-1, 0) to sign-extend to (-1, -1)
signalling overflow (the positive value doesn't fit in sizetype).
In the context of POINTER_PLUS_EXPRs the sizetype offset depending on
evaluation context has an effective range of [-INT_MIN, UINT_MAX].
So in principle we want to not treat the sign/zero extension
that happens when converting from/to sizetype as overflow.
--
rguenth at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
AssignedTo|pinskia at gcc dot gnu dot |rguenth at gcc dot gnu dot
|org |org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32628
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug middle-end/32628] [4.3 Regression] bogus integer overflow warning
2007-07-04 23:31 [Bug c/32628] New: bogus integer overflow warning ak at muc dot de
` (8 preceding siblings ...)
2008-01-15 15:03 ` rguenth at gcc dot gnu dot org
@ 2008-01-16 22:11 ` rguenth at gcc dot gnu dot org
2008-01-16 22:20 ` rguenth at gcc dot gnu dot org
2010-04-13 15:48 ` ebotcazou at gcc dot gnu dot org
11 siblings, 0 replies; 13+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2008-01-16 22:11 UTC (permalink / raw)
To: gcc-bugs
------- Comment #9 from rguenth at gcc dot gnu dot org 2008-01-16 21:52 -------
Subject: Bug 32628
Author: rguenth
Date: Wed Jan 16 21:51:57 2008
New Revision: 131579
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=131579
Log:
2008-01-16 Richard Guenther <rguenther@suse.de>
PR middle-end/32628
* fold-const.c (fold_convert_const_int_from_int): Do not
set overflow if that occured only because of a sign extension
change when converting from/to a sizetype with the same
precision and signedness.
* gcc.dg/overflow-warn-7.c: New testcase.
Added:
trunk/gcc/testsuite/gcc.dg/overflow-warn-7.c
Modified:
trunk/gcc/ChangeLog
trunk/gcc/fold-const.c
trunk/gcc/testsuite/ChangeLog
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32628
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug middle-end/32628] [4.3 Regression] bogus integer overflow warning
2007-07-04 23:31 [Bug c/32628] New: bogus integer overflow warning ak at muc dot de
` (9 preceding siblings ...)
2008-01-16 22:11 ` rguenth at gcc dot gnu dot org
@ 2008-01-16 22:20 ` rguenth at gcc dot gnu dot org
2010-04-13 15:48 ` ebotcazou at gcc dot gnu dot org
11 siblings, 0 replies; 13+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2008-01-16 22:20 UTC (permalink / raw)
To: gcc-bugs
------- Comment #10 from rguenth at gcc dot gnu dot org 2008-01-16 21:54 -------
Fixed.
--
rguenth at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution| |FIXED
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32628
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug middle-end/32628] [4.3 Regression] bogus integer overflow warning
2007-07-04 23:31 [Bug c/32628] New: bogus integer overflow warning ak at muc dot de
` (10 preceding siblings ...)
2008-01-16 22:20 ` rguenth at gcc dot gnu dot org
@ 2010-04-13 15:48 ` ebotcazou at gcc dot gnu dot org
11 siblings, 0 replies; 13+ messages in thread
From: ebotcazou at gcc dot gnu dot org @ 2010-04-13 15:48 UTC (permalink / raw)
To: gcc-bugs
------- Comment #11 from ebotcazou at gcc dot gnu dot org 2010-04-13 15:48 -------
Subject: Bug 32628
Author: ebotcazou
Date: Tue Apr 13 15:47:38 2010
New Revision: 158274
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=158274
Log:
PR middle-end/32628
* c-common.c (pointer_int_sum): Disregard overflow that occured only
because of sign-extension change when converting to sizetype here...
* fold-const.c (fold_convert_const_int_from_int): ...and not here.
* fold-const.c (fold_binary_op_with_conditional_arg): Do not restrict
the folding to constants. Remove redundant final conversion.
(fold_binary) <associate>: Do not associate if the re-association of
constants alone overflows.
(fold_binary) <FLOOR_MOD_EXPR>: Move transformation into BIT_AND_EXPR
to the end of the list.
(multiple_of_p) <COND_EXPR>: New case.
Modified:
trunk/gcc/ChangeLog
trunk/gcc/c-common.c
trunk/gcc/fold-const.c
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32628
^ permalink raw reply [flat|nested] 13+ messages in thread