[LLVMbugs] [Bug 9791] New: x86-64 Linux structure calling convention is wrong

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Mon Apr 25 01:15:46 PDT 2011


           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: unassignedbugs at nondot.org
        ReportedBy: edsrzf at gmail.com
                CC: llvmbugs at cs.uiuc.edu

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):

        movq    %rsi, %rax
        shrq    $32, %rax
        addl    %esi, %eax

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

    leal    (%rsi,%rdx), %eax

It looks like there's a problem in the backend that Clang's somehow working

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.

More information about the llvm-bugs mailing list