- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Bug report: Inlining of functions returning a 'call-clobbered' 64-bit register variable assigned by the output of GNU-style inline assembly may generate wrong code
Compiler: Intel icc v11.1.056 (flags -O2 -use-asm)
Platform: Linux Intel64 (Debian 5.0, gcc 4.3.2)
With -O2 flag the icc compiler inlines gnu_asm() and generates the following code:
The icc compiler generates code like 'k' would be a 'call-clobbered' register variable (in that case it would be legal to overwrite the previous assignment of k by the first printf call). The use of rdi as the register also results in wrong code.
Compiler: Intel icc v11.1.056 (flags -O2 -use-asm)
Platform: Linux Intel64 (Debian 5.0, gcc 4.3.2)
[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]
With -O2 flag the icc compiler inlines gnu_asm() and generates the following code:
[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]
The icc compiler generates code like 'k' would be a 'call-clobbered' register variable (in that case it would be legal to overwrite the previous assignment of k by the first printf call). The use of rdi as the register also results in wrong code.
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you for reporting here with testcase.
I'll filea bug reportfor this. If I heard anything, I'll let you know.
Jennifer
I'll filea bug reportfor this. If I heard anything, I'll let you know.
Jennifer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page