[Bug c/35753] apparent integer math bug
--- Comment #2 from rguenth at gcc dot gnu dot org 2008-03-29 10:27 --- use unsigned arithmetic. -- rguenth at gcc dot gnu dot org changed: What|Removed |Added Status|UNCONFIRMED |RESOLVED Resolution||INVALID http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35753
[Bug c/35753] apparent integer math bug
--- Comment #3 from regehr at cs dot utah dot edu 2008-03-29 19:16 --- Subject: Re: apparent integer math bug This multiplication overflows so the resulting behavior is undefined. Right-- but always in the past it has been (or seemed) fine to assume two's complement overflow behavior for signed arithmetic under gcc on two's complement platforms. I have seen the strict overflow options and those seem quite reasonable. However, changing overflow behavior for multiply seems risky! Is it still reasonable at least to rely on two's complement behavior for signed addition and subtraction? Thanks, John Regehr -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35753
Re: [Bug c/35753] apparent integer math bug
Sent from my iPhone On Mar 29, 2008, at 12:16, regehr at cs dot utah dot edu [EMAIL PROTECTED] wrote: --- Comment #3 from regehr at cs dot utah dot edu 2008-03-29 19:16 --- Subject: Re: apparent integer math bug This multiplication overflows so the resulting behavior is undefined. Right-- but always in the past it has been (or seemed) fine to assume two's complement overflow behavior for signed arithmetic under gcc on two's complement platforms. I have seen the strict overflow options and those seem quite reasonable. However, changing overflow behavior for multiply seems risky! Is it still reasonable at least to rely on two's complement behavior for signed addition and subtraction? It never was reasonable to depend on this behaviour, just GCC got better at optimizing these cases. We have had the option -fwrapv since at least 3.3 so that people can use that option if the want full wrapping behavior with signed types. Note the C standard is over 18 years old now so I had hoped people would still not making the mistake of thinking signed interger being wrapping types. Thanks, John Regehr -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35753
[Bug c/35753] apparent integer math bug
--- Comment #4 from pinskia at gmail dot com 2008-03-29 19:27 --- Subject: Re: apparent integer math bug Sent from my iPhone On Mar 29, 2008, at 12:16, regehr at cs dot utah dot edu [EMAIL PROTECTED] wrote: --- Comment #3 from regehr at cs dot utah dot edu 2008-03-29 19:16 --- Subject: Re: apparent integer math bug This multiplication overflows so the resulting behavior is undefined. Right-- but always in the past it has been (or seemed) fine to assume two's complement overflow behavior for signed arithmetic under gcc on two's complement platforms. I have seen the strict overflow options and those seem quite reasonable. However, changing overflow behavior for multiply seems risky! Is it still reasonable at least to rely on two's complement behavior for signed addition and subtraction? It never was reasonable to depend on this behaviour, just GCC got better at optimizing these cases. We have had the option -fwrapv since at least 3.3 so that people can use that option if the want full wrapping behavior with signed types. Note the C standard is over 18 years old now so I had hoped people would still not making the mistake of thinking signed interger being wrapping types. Thanks, John Regehr -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35753 -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35753
[Bug c/35753] apparent integer math bug
--- Comment #5 from regehr at cs dot utah dot edu 2008-03-29 19:32 --- Subject: Re: apparent integer math bug wrapping behavior with signed types. Note the C standard is over 18 years old now so I had hoped people would still not making the mistake of thinking signed interger being wrapping types. 18 years old and still useless for writing real programs! John Regehr -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35753
[Bug c/35753] apparent integer math bug
--- Comment #1 from pinskia at gmail dot com 2008-03-29 05:08 --- Subject: Re: New: apparent integer math bug Sent from my iPhone On Mar 28, 2008, at 21:40, regehr at cs dot utah dot edu [EMAIL PROTECTED] wrote: This is for gcc (GCC) 4.3.0. This function returns different values at -O1 and -O2: int func_5 (void) { int g_4 = 0x4E6D4F28; return 0 = (6 * g_4); } This multiplication overflows so the resulting behavior is undefined. -- pinski At -O1 output looks good: func_5: pushl %ebp movl%esp, %ebp movl$0, %eax popl%ebp ret At -O2 not good: func_5: pushl %ebp movl$1, %eax movl%esp, %ebp popl%ebp ret -- Summary: apparent integer math bug Product: gcc Version: 4.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: regehr at cs dot utah dot edu GCC build triplet: i686-pc-linux-gnu GCC host triplet: i686-pc-linux-gnu GCC target triplet: i686-pc-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35753 -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35753