public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "edwintorok at gmail dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/39736] signed overflow in loop induction variable: missing warning and wrong code Date: Mon, 13 Apr 2009 06:56:00 -0000 [thread overview] Message-ID: <20090413065621.7660.qmail@sourceware.org> (raw) In-Reply-To: <bug-39736-15165@http.gcc.gnu.org/bugzilla/> ------- Comment #5 from edwintorok at gmail dot com 2009-04-13 06:56 ------- (In reply to comment #4) > (In reply to comment #3) > > But converting from short to int for the argument to printf should behave as if > > a short value was converted to int, i.e. the int value should be in range > > -32768 to 32767, right? > > Usually but not here. Since you compiled with -fstrict-overflow (implicitly via > -O2) the compiler can assume your short variables will have proper short > values. As an optimisation the compiler could decide to store short variables > in wider int variables and to perform short arithmetic using int arithmetic. > Since you promised not to cause signed overflow those int variables would > always be the proper sign-extension of the corresponding short variables. > > But your test program does cause signed overflow, so this optimisation changes > behaviour. It's still not the compiler's fault. If you deliberately cause > signed overflow, do not compile with -fstrict-overflow. > Understood. Then this is not wrong code, just a missing warning. (In reply to comment #0) > There are 2 bugs here: > - no warning is given with -Wstrict-overflow=5, although -fstrict-overflow > changes the behaviour of the code This is still a bug: "It warns about cases where the compiler optimizes based on the assumption that signed overflow does not occur." > - from is of type short, so when sign extended to an int, it should only take > values allowed for a short: -32768 to 32767, not all values allowed for an int > (like 2253491) This is not a bug. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39736
next prev parent reply other threads:[~2009-04-13 6:56 UTC|newest] Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top 2009-04-11 12:30 [Bug tree-optimization/39736] New: " edwintorok at gmail dot com 2009-04-11 12:52 ` [Bug tree-optimization/39736] " joseph at codesourcery dot com 2009-04-12 9:11 ` mikpe at it dot uu dot se 2009-04-12 9:32 ` edwintorok at gmail dot com 2009-04-12 21:34 ` mikpe at it dot uu dot se 2009-04-13 6:56 ` edwintorok at gmail dot com [this message] 2009-04-13 7:53 ` schwab at linux-m68k dot org 2009-04-13 8:20 ` rguenth at gcc dot gnu dot org
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=20090413065621.7660.qmail@sourceware.org \ --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).