Bug 30935

Summary: Wrong evaluation result
Product: gcc Reporter: J. Römmler <jroemmler>
Component: cAssignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED DUPLICATE    
Severity: major CC: alexey, algorithmus, asokumar, av1474, bala, barnarr, behloul.younes, bmead15, buergel, carpman, chuchunxin, devnull, d_picco, eric.mcvicker, fuchsia.groan, gaurav_har, gcc-bugs, gcc, ggs, jandres, janis, jesser, jompo, krs, lid, lindahlb, lxg8906, mayer, mikaldaz, mike.clarkson, nakkore, nobs, pierre.van.de.laar_at_philips.com, qyang, ramiller, raoulgough, raphael.ribas, rglan, rjvbertin, robc, s9322036, SimonX200, smartmouse714, suan, super.aorta, svetozarmarkov, tczarnecki, vanveghel, vitaly, zshao
Priority: P3    
Version: 4.1.0   
Target Milestone: ---   
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.

Description J. Römmler 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 J. Römmler 2007-02-23 15:19:56 UTC
Created attachment 13099 [details]
Initial test case showing the bug.
Comment 2 J. Römmler 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 ***