From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20858 invoked by alias); 24 Feb 2003 21:26:00 -0000 Mailing-List: contact gcc-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-prs-owner@gcc.gnu.org Received: (qmail 20835 invoked by uid 71); 24 Feb 2003 21:26:00 -0000 Resent-Date: 24 Feb 2003 21:26:00 -0000 Resent-Message-ID: <20030224212600.20834.qmail@sources.redhat.com> Resent-From: gcc-gnats@gcc.gnu.org (GNATS Filer) Resent-Cc: gcc-prs@gcc.gnu.org, gcc-bugs@gcc.gnu.org Resent-Reply-To: gcc-gnats@gcc.gnu.org, gsasha@cs.technion.ac.il Received: (qmail 15475 invoked by uid 48); 24 Feb 2003 21:16:06 -0000 Message-Id: <20030224211606.15474.qmail@sources.redhat.com> Date: Mon, 24 Feb 2003 21:26:00 -0000 From: gsasha@cs.technion.ac.il Reply-To: gsasha@cs.technion.ac.il To: gcc-gnats@gcc.gnu.org X-Send-Pr-Version: gnatsweb-2.9.3 (1.1.1.1.2.31) Subject: optimization/9840: Incorrect optimization for floating-point aliasing to int X-SW-Source: 2003-02/txt/msg01293.txt.bz2 List-Id: >Number: 9840 >Category: optimization >Synopsis: Incorrect optimization for floating-point aliasing to int >Confidential: no >Severity: serious >Priority: medium >Responsible: unassigned >State: open >Class: wrong-code >Submitter-Id: net >Arrival-Date: Mon Feb 24 21:26:00 UTC 2003 >Closed-Date: >Last-Modified: >Originator: Alex Gontmakher >Release: gcc version 3.2.2 (Mandrake Linux 9.1 3.2.2-2mdk) >Organization: >Environment: machine: Athlon MP 1800 >Description: The following code worked with previous versions of GCC, producing either 1 or 0. Now it produces 2. A workaround is to uncomment the printf() line - obviously causes it to perform the initialization of the float prior to executing the ifs. The problem happens only at optimization level O2 or higher. >How-To-Repeat: #include int f() { int *p; double x = 1.0; /*fprintf(stderr,"");*/ /* NOTE: this check assumes IEEE floating point format */ p = (int *)&x; if (*p == 0) return 0; else if (*p == 0x3ff00000) return 1; else return 2; } int main() { std::cout << f() << std::endl; } >Fix: I didn't read the optimization code for this, but it should probably notice that p aliases &x, and perform the initialization of x prior to reading *p. >Release-Note: >Audit-Trail: >Unformatted: