From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23291 invoked by alias); 3 Dec 2002 14:36:02 -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 23274 invoked by uid 71); 3 Dec 2002 14:36:02 -0000 Resent-Date: 3 Dec 2002 14:36:02 -0000 Resent-Message-ID: <20021203143602.23273.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, pageexec@freemail.hu Received: (qmail 17187 invoked by uid 61); 3 Dec 2002 14:29:05 -0000 Message-Id: <20021203142905.17186.qmail@sources.redhat.com> Date: Tue, 03 Dec 2002 06:36:00 -0000 From: pageexec@freemail.hu Reply-To: pageexec@freemail.hu To: gcc-gnats@gcc.gnu.org X-Send-Pr-Version: gnatsweb-2.9.3 (1.1.1.1.2.31) Subject: optimization/8794: optimization improperly eliminates certain expressions X-SW-Source: 2002-12/txt/msg00138.txt.bz2 List-Id: >Number: 8794 >Category: optimization >Synopsis: optimization improperly eliminates certain expressions >Confidential: no >Severity: critical >Priority: medium >Responsible: unassigned >State: open >Class: wrong-code >Submitter-Id: net >Arrival-Date: Tue Dec 03 06:36:01 PST 2002 >Closed-Date: >Last-Modified: >Originator: PaX Team >Release: gcc 3.2.1 >Organization: >Environment: i386 linux (Athlon), kernel 2.4.20, locally compiled gcc 3.2.1 (--enable-shared --with-system-zlib --enable-nls --without-included-gettext --enable-__cxa_atexit --enable-clocale=gnu) >Description: the following code is miscompiled when any optimization (-O, -O2, etc) is enabled, works otherwise. the miscompiled code falsely evaluates the expression on the right hand side of += to nothing (ie. no code emitted for it, presumably because gcc thought that it was a constant 0 which is not true for values of 'addr' that are not aligned to ELF_PAGE_SIZE). example runs: good (gcc -o a.out a.c): a.out 0 -> 00000000 a.out 1 -> 00001001 a.out 4095 -> 00001FFF a.out 4096 -> 00001000 bad (gcc -O2 -o a.out a.c): a.out 1 -> 00000001 a.out 4095 -> 00000FFF it's also worth noting that in the real life code where this bug showed up we managed to get the optimized version to produce proper code by adding some extra expressions working on 'addr' before the ominous one (that may explain why it wasn't found already, it apparently needs some 'context' to show up). ------- cut ------- #include #include #define ELF_PAGE_SIZE 0x1000UL int main(int argc, char* argv[]) { unsigned long addr = atoi(argv[1]); addr += ELF_PAGE_SIZE - (ELF_PAGE_SIZE & (ELF_PAGE_SIZE - (addr & (ELF_PAGE_SIZE-1)))); printf("addr: %08lX\n", addr); return 0; } >How-To-Repeat: >Fix: >Release-Note: >Audit-Trail: >Unformatted: