* [Bug c/50922] infinite loop when optimized
2011-10-30 15:44 [Bug c/50922] New: infinite loop when optimized pfister at pci dot uzh.ch
@ 2011-10-30 16:26 ` xunxun1982 at gmail dot com
2011-10-30 17:03 ` mikpe at it dot uu.se
` (7 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: xunxun1982 at gmail dot com @ 2011-10-30 16:26 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50922
xunxun <xunxun1982 at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |xunxun1982 at gmail dot com
--- Comment #1 from xunxun <xunxun1982 at gmail dot com> 2011-10-30 16:26:26 UTC ---
I found that when combining -O1, -fstrict-overflow and -ftree-vrp, the infinite
loop occured.
And -O2 contains -O1, -fstrict-overflow and -ftree-vrp .
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c/50922] infinite loop when optimized
2011-10-30 15:44 [Bug c/50922] New: infinite loop when optimized pfister at pci dot uzh.ch
2011-10-30 16:26 ` [Bug c/50922] " xunxun1982 at gmail dot com
@ 2011-10-30 17:03 ` mikpe at it dot uu.se
2011-10-30 19:15 ` pinskia at gcc dot gnu.org
` (6 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: mikpe at it dot uu.se @ 2011-10-30 17:03 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50922
--- Comment #2 from Mikael Pettersson <mikpe at it dot uu.se> 2011-10-30 17:03:10 UTC ---
(In reply to comment #0)
> int main(void)
> {
> long x=0;
> unsigned long c;
> for(c=0;c<2147483648UL;c++)
> {
> lcdSendData(x++);
> }
You're causing a signed overflow in the "x++" expression. Try making x
"unsigned long" instead. Or pass "-fwrapv" to gcc.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c/50922] infinite loop when optimized
2011-10-30 15:44 [Bug c/50922] New: infinite loop when optimized pfister at pci dot uzh.ch
2011-10-30 16:26 ` [Bug c/50922] " xunxun1982 at gmail dot com
2011-10-30 17:03 ` mikpe at it dot uu.se
@ 2011-10-30 19:15 ` pinskia at gcc dot gnu.org
2011-10-31 7:38 ` pfister at pci dot uzh.ch
` (5 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu.org @ 2011-10-30 19:15 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50922
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> 2011-10-30 19:14:49 UTC ---
Signed integer overflow is undefined so this is invalid.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c/50922] infinite loop when optimized
2011-10-30 15:44 [Bug c/50922] New: infinite loop when optimized pfister at pci dot uzh.ch
` (2 preceding siblings ...)
2011-10-30 19:15 ` pinskia at gcc dot gnu.org
@ 2011-10-31 7:38 ` pfister at pci dot uzh.ch
2011-10-31 10:18 ` manu at gcc dot gnu.org
` (4 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: pfister at pci dot uzh.ch @ 2011-10-31 7:38 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50922
--- Comment #4 from Rolf Pfister <pfister at pci dot uzh.ch> 2011-10-31 07:38:01 UTC ---
Am 30.10.11 20:14, schrieb pinskia at gcc dot gnu.org:
> --- Comment #3 from Andrew Pinski<pinskia at gcc dot gnu.org> 2011-10-30 19:14:49 UTC ---
> Signed integer overflow is undefined so this is invalid.
>
If this is true, shouldnt the compiler give an error message or at least
a warning?
But I think incrementing is always well defined, even when overflowing.
And in the example the result after occuring the overflow is not
used anyway.
Rolf
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c/50922] infinite loop when optimized
2011-10-30 15:44 [Bug c/50922] New: infinite loop when optimized pfister at pci dot uzh.ch
` (3 preceding siblings ...)
2011-10-31 7:38 ` pfister at pci dot uzh.ch
@ 2011-10-31 10:18 ` manu at gcc dot gnu.org
2011-10-31 11:02 ` pfister at pci dot uzh.ch
` (3 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: manu at gcc dot gnu.org @ 2011-10-31 10:18 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50922
Manuel López-Ibáñez <manu at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |manu at gcc dot gnu.org
--- Comment #5 from Manuel López-Ibáñez <manu at gcc dot gnu.org> 2011-10-31 10:18:29 UTC ---
(In reply to comment #4)
> Am 30.10.11 20:14, schrieb pinskia at gcc dot gnu.org:
> > --- Comment #3 from Andrew Pinski<pinskia at gcc dot gnu.org> 2011-10-30 19:14:49 UTC ---
> > Signed integer overflow is undefined so this is invalid.
> >
> If this is true, shouldnt the compiler give an error message or at least
> a warning?
> But I think incrementing is always well defined, even when overflowing.
> And in the example the result after occuring the overflow is not
> used anyway.
http://gcc.gnu.org/wiki/FAQ#signed_overflow
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c/50922] infinite loop when optimized
2011-10-30 15:44 [Bug c/50922] New: infinite loop when optimized pfister at pci dot uzh.ch
` (4 preceding siblings ...)
2011-10-31 10:18 ` manu at gcc dot gnu.org
@ 2011-10-31 11:02 ` pfister at pci dot uzh.ch
2011-10-31 19:58 ` pfister at pci dot uzh.ch
` (2 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: pfister at pci dot uzh.ch @ 2011-10-31 11:02 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50922
--- Comment #6 from Rolf Pfister <pfister at pci dot uzh.ch> 2011-10-31 11:01:33 UTC ---
Am 31.10.11 11:18, schrieb manu at gcc dot gnu.org:
>
> http://gcc.gnu.org/wiki/FAQ#signed_overflow
>
Im not really convinced that the reason is the overflow.
Where is the overflow in this case?
long x=2147483647;
ulong c;
for(c=0;c<2147483648UL;c++)
{
lcdSendData(x--);
}
At least with "gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-48)"
this also gives an infinite loop.
Rolf
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c/50922] infinite loop when optimized
2011-10-30 15:44 [Bug c/50922] New: infinite loop when optimized pfister at pci dot uzh.ch
` (5 preceding siblings ...)
2011-10-31 11:02 ` pfister at pci dot uzh.ch
@ 2011-10-31 19:58 ` pfister at pci dot uzh.ch
2011-10-31 20:39 ` manu at gcc dot gnu.org
2011-11-01 7:26 ` pfister at pci dot uzh.ch
8 siblings, 0 replies; 10+ messages in thread
From: pfister at pci dot uzh.ch @ 2011-10-31 19:58 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50922
--- Comment #7 from Rolf Pfister <pfister at pci dot uzh.ch> 2011-10-31 19:58:07 UTC ---
I wrote:
> long x=2147483647;
> ulong c;
> for(c=0;c<2147483648UL;c++)
> {
> lcdSendData(x--);
> }
I tried this new variant with "gcc (Ubuntu 4.4.1-4ubuntu9) 4.4.1"
With this version it works correctly. Also with avr-gcc this variant
works correctly.
So the problem seems really to be solved.
Rolf
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c/50922] infinite loop when optimized
2011-10-30 15:44 [Bug c/50922] New: infinite loop when optimized pfister at pci dot uzh.ch
` (6 preceding siblings ...)
2011-10-31 19:58 ` pfister at pci dot uzh.ch
@ 2011-10-31 20:39 ` manu at gcc dot gnu.org
2011-11-01 7:26 ` pfister at pci dot uzh.ch
8 siblings, 0 replies; 10+ messages in thread
From: manu at gcc dot gnu.org @ 2011-10-31 20:39 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50922
--- Comment #8 from Manuel López-Ibáñez <manu at gcc dot gnu.org> 2011-10-31 20:38:17 UTC ---
(In reply to comment #7)
> I tried this new variant with "gcc (Ubuntu 4.4.1-4ubuntu9) 4.4.1"
> With this version it works correctly. Also with avr-gcc this variant
> works correctly.
> So the problem seems really to be solved.
I sincerely hope you are not doing something important with your code. Relying
on undefined behaviour sometimes "working" is like playing russian roulette.
That the last five times nothing bad happened does not tell you anything about
what will happen next time you try.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [Bug c/50922] infinite loop when optimized
2011-10-30 15:44 [Bug c/50922] New: infinite loop when optimized pfister at pci dot uzh.ch
` (7 preceding siblings ...)
2011-10-31 20:39 ` manu at gcc dot gnu.org
@ 2011-11-01 7:26 ` pfister at pci dot uzh.ch
8 siblings, 0 replies; 10+ messages in thread
From: pfister at pci dot uzh.ch @ 2011-11-01 7:26 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50922
--- Comment #9 from Rolf Pfister <pfister at pci dot uzh.ch> 2011-11-01 07:25:53 UTC ---
Am 31.10.11 21:38, schrieb manu at gcc dot gnu.org:
>
> I sincerely hope you are not doing something important with your code. Relying
No, I dont use this code in my own programs. It was just the first
example program coming with a new hardware device.
Now when someone will ask again in the forum, I can tell them that it is
a bug in the program and not in the compiler.
http://myavr.info/myForum/viewtopic.php?t=2974
Rolf
^ permalink raw reply [flat|nested] 10+ messages in thread