Consider the following simplified example function:
void foo(void) {
    int t;
    asm("push %0\n\t"
        "push %0\n\t"
        "call bar"
        :
        : "m" (t)
        :
        );
}
If I compile it with Cygwin x86 gcc 4.8.3 without optimization, the push instructions become:
push -4(%ebp)
push -4(%ebp)
This is good. The problem happens with -O:
push 12(%esp)
push 12(%esp)
This is clearly wrong. The first push changes esp, and the second push then accesses the wrong location. I have read that adding "%esp" to the clobber list should fix it, but it does not help. How can I make GCC use a frame pointer or properly consider esp changes?
(Assume that returning from the bar function will set esp to the value it had before the asm statement. I just need to call a thiscall function and am using inline assembly for that.)
 
    