http://llvm.org/bugs/show_bug.cgi?id=9791
Summary: x86-64 Linux structure calling convention is wrong
Product: libraries
Version: 2.9
Platform: PC
OS/Version: Linux
Status: NEW
Severity: normal
Priority: P
Component: Backend: X86
AssignedTo: [email protected]
ReportedBy: [email protected]
CC: [email protected]
Code generated by the X86-64 backend does not follow the Linux calling
convention for structure passing. Consider this structure:
struct s {
int* a;
int b, c;
};
Clang and GCC both correctly pass the struct in two registers: one for the
pointer and one for the other two fields. Here's an example:
C function:
int foo(struct s x) {
return x.b + x.c;
}
Assembly (with -O2):
foo:
movq %rsi, %rax
shrq $32, %rax
addl %esi, %eax
ret
This is the IR for the equivalent function:
%struct = type { i32*, i32, i32 }
define i32 @foo(%struct %x) {
%b = extractvalue %slice %x, 1
%c = extractvalue %slice %x, 2
%sum = add i32 %b, %c
ret i32 %sum
}
When this is assembled with llvm-as and has the standard compile optimizations
run on it, it compiles to this assembly, which passes the struct in three
registers:
foo:
leal (%rsi,%rdx), %eax
ret
It looks like there's a problem in the backend that Clang's somehow working
around.
--
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs