public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "eskil at obsession dot se" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c/46899] compiler optimization Date: Sun, 12 Dec 2010 12:30:00 -0000 [thread overview] Message-ID: <bug-46899-4-ReyeZoIERn@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 --- Comment #5 from Eskil Steenberg <eskil at obsession dot se> 2010-12-12 12:30:15 UTC --- Hi >>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 there is since a and c are promoted to signed ints and thats where the multiplication takes place, before they are converted to an unsigned int. A max unsigned short times a max unsigned short will overflow a signed int. (given a 32 bit system at least) >> 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. So how can the compiler make a compile time assumption about the outcome of the behavior since it is undefined at compile time? >> 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. Could you clarify this statement? > Unless you can give a testcase that does not depend on undefined behavior, > it is hard to prove GCC is doing something wrong. The very problem I'm addressing is how gcc deals with this, at compile time, undefined behavior. Cheers E
next prev parent reply other threads:[~2010-12-12 12:30 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 2010-12-12 12:30 ` eskil at obsession dot se [this message] 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-ReyeZoIERn@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).