[cpp]// Sample code: compile with -O2 -use-asm #includelong gnu_asm (void) { // defining a specific register is usually a bad idea, but GNU gcc allows this register long regvar __asm__ ("rax"); __asm__ ( " movq $12345, %0 " : "=r"(regvar) ); // rax is a 'call-clobbered' register, but there are no function calls between // assignment and return statement. Therefore the return value must be 12345. return regvar; } int main(int argc, char *argv[]) { long k; k = gnu_asm(); printf("A printf() function call to clobber the rax register.n"); printf("Output here should be 12345, but it's the return value of previous printf(): '%ld'n", k); return 0; } [/cpp]
[plain] ... movq $12345, %rax movl $_2__STRING.0, %edi xorl %eax, %eax call printf movl $_2__STRING.1, %edi movq %rax, %rsi xorl %eax, %eax call printf ... [/plain]
Link Copied
Hi,
I'm working through old open forum posts at the moment. Sorry for answering so
late. I tested your example code again with the latest 11.1.075 compiler and it
works now. The issue is fixed.
Thanks again for reporting this issue with such a nice testcase!
Alexander
For more complete information about compiler optimizations, see our Optimization Notice.