public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
From: algrant@acm.org
To: gcc-gnats@gcc.gnu.org
Subject: c/7284: incorrectly simplifies leftshift followed by signed power-of-2 division
Date: Fri, 12 Jul 2002 04:26:00 -0000	[thread overview]
Message-ID: <20020712112526.9569.qmail@sources.redhat.com> (raw)


>Number:         7284
>Category:       c
>Synopsis:       incorrectly simplifies leftshift followed by signed power-of-2 division
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          wrong-code
>Submitter-Id:   net
>Arrival-Date:   Fri Jul 12 04:26:00 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     Al Grant
>Release:        3.1
>Organization:
>Environment:
SunOS 5.5.1 Generic_103640-31 sun4u sparc SUNW,Ultra-5_10
>Description:
Incorrect simplification of signed 

  (n << 24) / (1 << 23)

to a single left shift.  Should sign-extend from bit 8.
>How-To-Repeat:
#include <stdio.h>
int f(int n) { return (n<<24) / (1<<23); }
int main(void) { 
  if (f(128) != -256) printf("Broken\n"); return 0; }
>Fix:
Replace with left shift followed by signed right shift.
This can be done in source as a workaround.
>Release-Note:
>Audit-Trail:
>Unformatted:


             reply	other threads:[~2002-07-12 11:26 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-07-12  4:26 algrant [this message]
2002-07-12  7:12 nathan
2002-07-12  8:06 Al Grant
2002-07-12  8:16 Falk Hueffner
2002-07-12  9:26 Falk Hueffner
2002-07-12  9:46 Nathan Sidwell
2002-07-12 10:06 Falk Hueffner
2002-07-12 12:56 Nathan Sidwell
2003-02-13 16:06 rearnsha

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=20020712112526.9569.qmail@sources.redhat.com \
    --to=algrant@acm.org \
    --cc=gcc-gnats@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: link
Be 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).