public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* optimization/8794: optimization improperly eliminates certain expressions
@ 2002-12-03  6:36 pageexec
  0 siblings, 0 replies; 2+ messages in thread
From: pageexec @ 2002-12-03  6:36 UTC (permalink / raw)
  To: gcc-gnats


>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 <stdio.h>
#include <stdlib.h>

#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:


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: optimization/8794: optimization improperly eliminates certain expressions
@ 2002-12-03  8:26 Christian Ehrhardt
  0 siblings, 0 replies; 2+ messages in thread
From: Christian Ehrhardt @ 2002-12-03  8:26 UTC (permalink / raw)
  To: nobody; +Cc: gcc-prs

The following reply was made to PR optimization/8794; it has been noted by GNATS.

From: "Christian Ehrhardt" <ehrhardt@mathematik.uni-ulm.de>
To: pageexec@freemail.hu
Cc: gcc-gnats@gcc.gnu.org, gcc-bugs@gcc.gnu.org
Subject: Re: optimization/8794: optimization improperly eliminates certain expressions
Date: Tue, 3 Dec 2002 17:24:08 +0100

 On Tue, Dec 03, 2002 at 02:29:05PM -0000, pageexec@freemail.hu wrote:
 > >Number:         8794
 > >Category:       optimization
 > >Synopsis:       optimization improperly eliminates certain expressions
 > >Release:        gcc 3.2.1
 
 Confirmed on i686. The orignal example works ok on sparc but a slightly
 simplified example produces bad code on sparc with 3.2.1 and 3.3:
 
 ------------- cut ------------------
 unsigned int addr;
 void f (void)
 {
 	addr = (1024 & (1024UL - (addr & 1023UL)));
 }
 ------------- cut ------------------
 
 Is compiled into:
 
 ------------- cut ------------------
 	.file	"8794.c"
 	.section	".text"
 	.align 4
 	.global f
 	.type	f,#function
 	.proc	020
 f:
 	!#PROLOGUE# 0
 	!#PROLOGUE# 1
 	mov	1024, %o1
 	sethi	%hi(addr), %o0
 	retl
 	st	%o1, [%o0+%lo(addr)]
 .LLfe1:
 	.size	f,.LLfe1-f
 	.common	addr,4,4
 	.ident	"GCC: (GNU) 3.2.1 20021111 (prerelease)"
 ------------- cut ------------------
 
 Which is clearly wrong. The necessary instructions are elimiated by
 between 8794.c.15.life and 8794.c.16.combine.
 
       regards   Christian
 
 -- 
 THAT'S ALL FOLKS!


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2002-12-03 16:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-12-03  6:36 optimization/8794: optimization improperly eliminates certain expressions pageexec
2002-12-03  8:26 Christian Ehrhardt

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).