public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "ian at airs dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c/55771] New: Negation and type conversion incorrectly exchanged Date: Fri, 21 Dec 2012 04:52:00 -0000 [thread overview] Message-ID: <bug-55771-4@http.gcc.gnu.org/bugzilla/> (raw) http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55771 Bug #: 55771 Summary: Negation and type conversion incorrectly exchanged Classification: Unclassified Product: gcc Version: 4.8.0 Status: UNCONFIRMED Keywords: wrong-code Severity: normal Priority: P3 Component: c AssignedTo: unassigned@gcc.gnu.org ReportedBy: ian@airs.com This program should print the same thing twice: #include <stdio.h> void f1() { unsigned long x = 3; float y = 1; printf ("%g\n", (-x) * y); } void f2() { unsigned long x = 3; float y = 1; unsigned long z = - x; printf ("%g\n", z * y); } int main() { f1(); f2(); } However, on x86_64 GNU/Linux with current mainline, it prints -3 1.84467e+19 It is already incorrect in the first GIMPLE dump. f1 has x = 3; y = 1.0e+0; D.2219 = (float) x; D.2220 = -D.2219; f2 has x = 3; y = 1.0e+0; z = -x; D.2223 = (float) z; In other words, in f1, the conversion to float happens before the negation. The bug happens with both the C and C++ frontends.
next reply other threads:[~2012-12-21 4:52 UTC|newest] Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top 2012-12-21 4:52 ian at airs dot com [this message] 2012-12-21 5:27 ` [Bug c/55771] " ppluzhnikov at google dot com 2012-12-21 6:59 ` xinliangli at gmail dot com 2012-12-21 9:00 ` mikpe at it dot uu.se 2012-12-21 10:07 ` mikpe at it dot uu.se 2012-12-21 10:10 ` rguenth at gcc dot gnu.org 2012-12-21 13:29 ` ian at airs dot com 2012-12-21 13:53 ` [Bug middle-end/55771] " rguenth at gcc dot gnu.org 2012-12-21 13:56 ` rguenth at gcc dot gnu.org 2012-12-21 13:58 ` rguenth at gcc dot gnu.org 2012-12-21 13:59 ` jakub at gcc dot gnu.org 2012-12-21 14:09 ` jakub at gcc dot gnu.org 2013-07-12 13:23 ` matz at gcc dot gnu.org 2021-08-18 21:53 ` pinskia at gcc dot gnu.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=bug-55771-4@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).