Bug 30935 - Wrong evaluation result
Wrong evaluation result
Status: RESOLVED DUPLICATE of bug 11751
Product: gcc
Classification: Unclassified
Component: c
4.1.0
: P3 major
: ---
Assigned To: Not yet assigned to anyone
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2007-02-23 15:18 UTC by Jochen Roemmler
Modified: 2007-03-30 13:36 UTC (History)
50 users (show)

See Also:
Host: x86_64-redhat-linux
Target: x86_64-redhat-linux
Build: x86_64-redhat-linux
Known to work:
Known to fail:
Last reconfirmed:


Attachments
Initial test case showing the bug. (391 bytes, text/plain)
2007-02-23 15:19 UTC, Jochen Roemmler
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jochen Roemmler 2007-02-23 15:18:01 UTC
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)
Comment 1 Jochen Roemmler 2007-02-23 15:19:56 UTC
Created attachment 13099 [details]
Initial test case showing the bug.
Comment 2 Jochen Roemmler 2007-02-23 15:22:07 UTC
(In reply to comment #0)
> The machine is a Fedora Core 6 Linux x86_64 box.

Sorry, I meant "Fedora Core release 5 (Bordeaux)"
Comment 3 Richard Biener 2007-02-23 15:36:11 UTC

*** This bug has been marked as a duplicate of 11751 ***