public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "jrr at concept dot de" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/30935]  New: Wrong evaluation result
Date: Fri, 23 Feb 2007 15:18:00 -0000	[thread overview]
Message-ID: <bug-30935-9784@http.gcc.gnu.org/bugzilla/> (raw)

The following C program evaluates t.a to a *wrong* value of 5 instead of 9:

#include <stdio.h>

struct test {
    int a;
};

int func(struct test* tp) {
    tp->a = 8;  /* this update is lost */
    return 1;
}

int main(int ac, char** av) {
    struct test t;
    t.a = 4;

    t.a += func(&t);   /* t.a (=4) already loaded into a CPU register? */

    printf("t.a=%d ", t.a);
    if (t.a == 9) {
        printf("OK\n");
        return 0;
    } else {
        printf("BAD\n");
        return 1;
    }
}

# gcc bad_eval.c && ./a.out
t.a=5 BAD

The machine is a Fedora Core 6 Linux x86_64 box.

# uname -a
Linux titan 2.6.16-1.2080_FC5 #1 SMP Tue Mar 28 03:38:47 EST 2006 x86_64 x86_64
x86_64 GNU/Linux

# gcc -v
Using built-in specs.
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --enable-shared --enable-threads=posix
--enable-checking=release --with-system-zlib --enable-__cxa_atexit
--disable-libunwind-exceptions --enable-libgcj-multifile
--enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk
--disable-dssi --with-java-home=/usr/lib/jvm/java-1.4.2-gcj-1.4.2.0/jre
--with-cpu=generic --host=x86_64-redhat-linux
Thread model: posix
gcc version 4.1.0 20060304 (Red Hat 4.1.0-3)


-- 
           Summary: Wrong evaluation result
           Product: gcc
           Version: 4.1.0
            Status: UNCONFIRMED
          Severity: major
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: jrr at concept dot de
 GCC build triplet: x86_64-redhat-linux
  GCC host triplet: x86_64-redhat-linux
GCC target triplet: x86_64-redhat-linux


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30935


             reply	other threads:[~2007-02-23 15:18 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-02-23 15:18 jrr at concept dot de [this message]
2007-02-23 15:20 ` [Bug c/30935] " jrr at concept dot de
2007-02-23 15:22 ` jrr at concept dot de
2007-02-23 15:36 ` rguenth at gcc dot gnu dot 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-30935-9784@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: 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).