https://bugs.llvm.org/show_bug.cgi?id=42394
Bug ID: 42394
Summary: The preserve_all and preserve_most calling conventions
on X86 trash the return value.
Product: clang
Version: trunk
Hardware: PC
OS: Linux
Status: NEW
Severity: normal
Priority: P
Component: -New Bugs
Assignee: [email protected]
Reporter: [email protected]
CC: [email protected], [email protected],
[email protected], [email protected]
The preserve_all and preserve_most calling convention attributes are meant to
save and restore more than just the normal callee-save set of registers.
However, at least on x86, they seem to save and restore the return register
also, thus trashing the return value.
//--------------------
#include <stdio.h>
int __attribute__((preserve_most)) foo(int x) { return x+1; }
int main() { printf("%d %d\n", foo(1), foo(2)); }
//--------------------
$ clang -o p.out p.cpp
$ .\p.out
4195616 4195616
Interestingly, with -O2, the result is correct because foo gets inlined. If the
caller and the callee are in two different files, -O2 shows the same problem.
The assembly code shows clearly what is happening:
_Z3fooi: # @_Z3fooi
pushq %rdi
pushq %rax
leal 1(%rdi), %eax
popq %rax <--- return value trashed
popq %rdi
retq
--
You are receiving this mail because:
You are on the CC list for the bug._______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs