#ifdef __i386__
#include <cstdio>
struct obj
{
        void foo()
        {
                std::printf( "foo(): this -> %p, val = %d\n",
                        (void*)this, val );
        }
        int val;
};
void test( obj& o )
{
        o.foo();
}
int main()
{
        obj x;
        x.val = 7;
        asm volatile
        (
                "push   %1              \n\t"
                "call   *%0             \n\t"
                "add    $4, %%esp       \n\t"
                :
                : "r" ( &test ), "r" ( &x )
        );
        return 0;
};
#endif

$ g++ test.cpp -m32 -Wall -O1 && ./a.out
foo(): this -> 0xffffc610, val = -135843852

$ g++ test.cpp -m32 -Wall -O1 -fno-tree-dce && ./a.out
foo(): this -> 0xffffcfd0, val = 7


-- 
           Summary: tree-dce incorrectly removes an assignment.
           Product: gcc
           Version: 4.1.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: pluto at agmk dot net
GCC target triplet: ix86-linux


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

Reply via email to