public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
From: pageexec@freemail.hu
To: gcc-gnats@gcc.gnu.org
Subject: optimization/8794: optimization improperly eliminates certain expressions
Date: Tue, 03 Dec 2002 06:36:00 -0000	[thread overview]
Message-ID: <20021203142905.17186.qmail@sources.redhat.com> (raw)


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


             reply	other threads:[~2002-12-03 14:36 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-12-03  6:36 pageexec [this message]
2002-12-03  8:26 Christian Ehrhardt

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=20021203142905.17186.qmail@sources.redhat.com \
    --to=pageexec@freemail.hu \
    --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).