public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "pinskia at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c/46899] compiler optimization Date: Sun, 12 Dec 2010 10:20:00 -0000 [thread overview] Message-ID: <bug-46899-4-vcpcK8cC6H@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-46899-4@http.gcc.gnu.org/bugzilla/> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46899 Andrew Pinski <pinskia at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |RESOLVED Resolution| |INVALID --- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> 2010-12-12 10:20:03 UTC --- >Sorry it underflows. No, conversion does not have any overflow/underflow in it. >void my_func(unsigned short a, unsigned short c) >{ > unsigned int b; > > b = a * c; There is no overflow here since this unsigned integers wrap and don't overflow. > Yes, but the doesn't the C spec define the overflow as undefined, rather > then the entire program? No it is a runtime undefined behavior rather than the result being undefined. > rather that gcc makes assumptions about this behavior that _can_ turn out to > be not true. But assumptions? Since it is undefined behavior, it does not matter because GCC can make different assumptions in when it feels like. Unless you can give a testcase that does not depend on undefined behavior, it is hard to prove GCC is doing something wrong. -fwrapv can be used to define signed integer overflow as wrapping. See http://gcc.gnu.org/onlinedocs/gcc-4.5.1/gcc/Integers-implementation.html for how the conversion is implementation defined behavior: > # The result of, or the signal raised by, converting an integer to a signed > integer type when the value cannot be represented in an object of that type > (C90 6.2.1.2, C99 6.3.1.3). > For conversion to a type of width N, the value is reduced modulo 2^N to be > within range of the type; no signal is raised. Conversions are never causes an overflow rather it causes an implementation defined behavior in some cases.
next prev parent reply other threads:[~2010-12-12 10:20 UTC|newest] Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top 2010-12-12 0:35 [Bug c/46899] New: " eskil at obsession dot se 2010-12-12 1:54 ` [Bug c/46899] " pinskia at gcc dot gnu.org 2010-12-12 1:56 ` pinskia at gcc dot gnu.org 2010-12-12 9:10 ` eskil at obsession dot se 2010-12-12 10:20 ` pinskia at gcc dot gnu.org [this message] 2010-12-12 12:30 ` eskil at obsession dot se 2010-12-12 21:03 ` pinskia at gcc dot gnu.org 2010-12-12 21:46 ` eskil at obsession dot se 2010-12-12 21:52 ` pinskia at gcc dot gnu.org 2010-12-12 22:23 ` eskil at obsession dot se 2010-12-13 0:21 ` schwab@linux-m68k.org 2010-12-13 14:09 ` eskil at obsession dot se
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-46899-4-vcpcK8cC6H@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).