[LLVMbugs] [Bug 20302] New: small arguments stored on stack in high words on MIPS64

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Mon Jul 14 15:08:48 PDT 2014


            Bug ID: 20302
           Summary: small arguments stored on stack in high words on
           Product: clang
           Version: trunk
          Hardware: SGI
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: LLVM Codegen
          Assignee: unassignedclangbugs at nondot.org
          Reporter: msebor at gmail.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

When passing more than 8 scalar arguments to a function on big-endian MIPS64
(both the N32 and N64 ABIs), the ninth and subsequent arguments are spilled to
the stack (the first 8 arguments are passed in 64-bit integer registers).
Arguments that are smaller than 64-bits such as int must be stored by the
caller in and retrieved by the callee from the low word of the corresponding
stack slot. The test case below shows that Clang stores them in and retrieves
them from the high word, generating ABI-incompatible code. See also clang bug
19612 for a related problem involving vararg functions.

$ cat u.c && /auto/binos-tools/llvm-3.4.0/bin/clang -DFOO -O2 -S
--target=mips64 u.c && cat u.s
extern int foo (int, int, int, int, int, int, int, int, int);
int bar (int a, int b, int c, int d, int e, int f, int g, int h, int i) {
    return i;
int baz (void) { return foo (1, 2, 3, 4, 5, 6, 7, 8, 9); }
    .section .mdebug.abi64
    .file    "u.c"
    .globl    bar
    .align    3
    .type    bar, at function
    .set    nomips16
    .ent    bar
    .frame    $fp,16,$ra
    .mask     0x00000000,0
    .fmask    0x40000000,-4
    .set    noreorder
    .set    nomacro
    .set    noat
    daddiu    $sp, $sp, -16
    sd    $fp, 8($sp)
    move     $fp, $sp
    lw    $2, 16($fp)               <<< SHOULD BE lw $2, 20($sp)
    move     $sp, $fp
    ld    $fp, 8($sp)
    jr    $ra
    daddiu    $sp, $sp, 16
    .set    at
    .set    macro
    .set    reorder
    .end    bar
    .size    bar, ($tmp3)-bar

    .globl    baz
    .align    3
    .type    baz, at function
    .set    nomips16
    .ent    baz
    .frame    $fp,48,$ra
    .mask     0x00000000,0
    .fmask    0xd0000000,-4
    .set    noreorder
    .set    nomacro
    .set    noat
    daddiu    $sp, $sp, -48
    sd    $ra, 40($sp)
    sd    $fp, 32($sp)
    sd    $gp, 24($sp)
    move     $fp, $sp
    lui    $1, %hi(%neg(%gp_rel(baz)))
    daddu    $1, $1, $25
    daddiu    $1, $1, %lo(%neg(%gp_rel(baz)))
    addiu    $2, $zero, 9
    sw    $2, 0($sp)               <<< SHOULD BE sw $2, 4($sp)
    ld    $25, %call16(foo)($1)
    addiu    $4, $zero, 1
    addiu    $5, $zero, 2
    addiu    $6, $zero, 3
    addiu    $7, $zero, 4
    addiu    $8, $zero, 5
    addiu    $9, $zero, 6
    addiu    $10, $zero, 7
    addiu    $11, $zero, 8
    jalr    $25
    move     $gp, $1
    move     $sp, $fp
    ld    $gp, 24($sp)
    ld    $fp, 32($sp)
    ld    $ra, 40($sp)
    jr    $ra
    daddiu    $sp, $sp, 48
    .set    at
    .set    macro
    .set    reorder
    .end    baz
    .size    baz, ($tmp7)-baz

    .ident    "clang version 3.4 (ssh://wwwin-git-sjc-2/git/llvm/clang.git
74a0c210785e337b942d9393e6e2ab26dda43f63) (llvm/llvm.git

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/20140714/1ed8f58b/attachment.html>

More information about the llvm-bugs mailing list