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

Josh Haberman <jhaberman at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |UNCONFIRMED
         Resolution|INVALID                     |

--- Comment #2 from Josh Haberman <jhaberman at gmail dot com> 2012-04-01 
15:54:27 UTC ---
I don't expect the compiler to analyze the asm string.  I expect the compiler
to respect my clobber list.

I told GCC that I would clobber %rsp.  Any other register that I put in the
clobber list causes GCC to save that register to the stack or to another
register before the asm and restore it from the stack/register after the asm. 
For example:

--

#include <stdlib.h>
int main() {
  int x = rand();
  asm volatile ("movq $0, %%rax" : : : "%rax");
  return x;
}

$ gcc -Wall -O3 -fomit-frame-pointer -c -o test.o test.c
$ objdump -d -r -M intel test.o
test.o:     file format elf64-x86-64


Disassembly of section .text.startup:

0000000000000000 <main>:
   0:    48 83 ec 08              sub    rsp,0x8
   4:    e8 00 00 00 00           call   9 <main+0x9>
            5: R_X86_64_PC32    rand-0x4
   9:    89 c2                    mov    edx,eax
   b:    48 c7 c0 00 00 00 00     mov    rax,0x0
  12:    89 d0                    mov    eax,edx
  14:    48 83 c4 08              add    rsp,0x8
  18:    c3                       ret

--

Notice that it saved eax to edx before my asm and restored it afterwards.  This
works for every register except %rsp, which is silently ignored if you try to
list it in the clobber list.  This is a bug.

Reply via email to