[llvm-bugs] [Bug 42394] New: The preserve_all and preserve_most calling conventions on X86 trash the return value.
via llvm-bugs
llvm-bugs at lists.llvm.org
Tue Jun 25 14:30:27 PDT 2019
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: unassignedclangbugs at nondot.org
Reporter: sunil_srivastava at playstation.sony.com
CC: htmldeveloper at gmail.com, llvm-bugs at lists.llvm.org,
neeilans at live.com, richard-llvm at metafoo.co.uk
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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20190625/5c74484b/attachment-0001.html>
More information about the llvm-bugs
mailing list