Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: gcc failure (optimised/non-optimised) Date: Sun, 30 Apr 2017 13:59:23 -0700 Organization: None to speak of Lines: 35 Message-ID: References: <58fb2265.5246218@news.xs4all.nl> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="518c2254bac820b1cb24a1d9d6a93e31"; logging-data="26684"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+NMKYWFfwxZWupFhSDvRvA" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:9p8y3qccQMk8H/lUQb4IHJz+LkM= sha1:DPsdWo2WHqtcmVvqvmMHj84Cp4k= Xref: csiph.com comp.lang.c:108806 Noob writes: > On 30/04/2017 19:08, supercat@casperkitty.com wrote: >> On Sunday, April 30, 2017 at 9:50:09 AM UTC-5, Noob wrote: >>> Does anyone disagree that an optimizing compiler would >>> determine that this is the identity function, and would >>> drop the calls altogether, by replacing foo(x) with x. >> >> That would depend upon what, if anything, the compiler documents about the >> behavior of integer overflow. > > Are you confusing IDB and UB? I obviously can't speak for supercat, but I doubt it. > Why would any compiler document the behavior of signed overflow? > Are you thinking of some extension? A implementation is permitted to document the behavior of constructs that have undefined behavior according to the C standard. "gcc -fwrapv" is one implementation that does so for signed integer overflow ("gcc -fwrapv" can be thought of as a distinct implementation from gcc without "-fwrapv"). I wouldn't say it's necessary to think of this as an "extension", since the behavior is consistent with what the standard requires. (Nothing in the standard requires an implementation to obey its own documentation, except arguably for documentation that's required by the standard, so if "gcc -fwrapv" didn't work as specified it would be a bug in gcc, but not a conformance violation.) -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"