|
From: | Robert Dewar |
Subject: | Re: GCC optimizes integer overflow: bug or feature? |
Date: | Tue, 19 Dec 2006 08:34:48 -0500 |
User-agent: | Thunderbird 1.5.0.8 (Windows/20061025) |
Joseph S. Myers wrote:
On Tue, 19 Dec 2006, Florian Weimer wrote:* Paolo Bonzini:Interesting read. I agree with the proposed fix; however, note that GCC does not make the result of overflowing signed left-shifts undefined, exactly because in this case the overflow is relied upon by too many existing programsIs this documented somewhere? Without documentation, it could also be an oversight (lack of optimization) from a programmer perspective.Certainly, in implement-c.texi: GCC does not use the latitude given in C99 only to treat certain aspects of signed @samp{<<} as undefined, but this is subject to change.
That hardly seems sufficient documentation, when documenting undefined, you had better say what the semantics is. Saying it is not treated as undefined, and then failing to define it is a bit of a contradiction in terms :-)
This particular case has the special property that signed << was implementation-defined in C90 (DR#081) and became undefined in some cases in C99.We've optimized expressions such as (a*2)/2 on the basis of overflow being undefined for a very long time, not just loops.
What is (a*2)/2 optimized to? certainly it has the value a if you wrap, so you are not necessarily depending on undefined here.
[Prev in Thread] | Current Thread | [Next in Thread] |