Description of Problem: gcc miscompiles code with -O2, correct with -O0 Version-Release number of selected component (if applicable): gcc-2.96-98 How Reproducible: compile the attachment options: gcc -O2 -fomit-frame-pointer -o bad badgcc.cpp gcc -O0 -fomit-frame-pointer -o good badgcc.cpp run it. Actual Results: got tsd 2152509265989 at esp=bffffb20h for time=bffffb50h. got tsd 2152539497047 at esp=bffffb20h for time=bffffb48h. needed 30231058 cycles (3.023106/call). got tsd 2154240734828 at esp=bffffb20h for time=bffffb40h. ^^^^^^^ got tsd 2154270773195 at esp=bffffb20h for time=bffffb48h. must be b50, not b40. Expected Results: got tsd 2143396909839 at esp=bffffb00h for time=bffffb60h. got tsd 2143484049795 at esp=bffffb00h for time=bffffb58h. needed 87139956 cycles (8.713996/call). got tsd 2145186785406 at esp=bffffb00h for time=bffffb60h. got tsd 2145273718039 at esp=bffffb00h for time=bffffb58h. needed 86932633 cycles (8.693263/call). Additional Information:
Created attachment 35262 [details] test app
gcc 3.0 and gcc 3.1 behave similarly. gcc handles *FRAME_POINTER registers specially apparently, even with -fomit-frame-pointer, when needed.
This is dodgy code at best, but gcc 3.4 will at least give z.c:58: error: bp cannot be used in asm here instead of generating code that crashes.