[Bug target/95526] New: aarch64: Wrong code accessing complex number from varargs

acoplan at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Thu Jun 4 09:24:49 GMT 2020


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95526

            Bug ID: 95526
           Summary: aarch64: Wrong code accessing complex number from
                    varargs
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: major
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: acoplan at gcc dot gnu.org
  Target Milestone: ---

Commit eb72dc663e9070b281be83a80f6f838a3a878822 introduces a wrong code bug on
AArch64.

This causes the test case gcc/testsuite/gcc.dg/complex-1.c to start failing.
This test case can be reduced to the following program:

  extern void abort(void);

  void f(unsigned x, ...)
  {
    __builtin_va_list ap;
    _Complex float cf;

    __builtin_va_start(ap, x);
    cf = __builtin_va_arg(ap, _Complex float);
    __builtin_va_end(ap);

    if (__imag__ cf != 2.0f)
      abort();
  }

  int main(void)
  {
    f(0, 2.0fi);
  }

which calls abort() at both -O0 and -O2 after this patch. Prior to this patch,
we get the following code for f at -O2:

f:
.LFB0:
        .cfi_startproc
        stp     x29, x30, [sp, -80]!
        .cfi_def_cfa_offset 80
        .cfi_offset 29, -80
        .cfi_offset 30, -72
        mov     x29, sp
        str     q1, [sp, 64]
        fmov    s1, 2.0e+0
        add     x0, sp, 80
        ldr     s2, [sp, 64]
        stp     x0, x0, [sp, 16]
        fcmp    s2, s1
        str     x0, [sp, 32]
        stp     wzr, wzr, [sp, 40]
        str     q0, [sp, 48]
        bne     .L8
        ldp     x29, x30, [sp], 80
        .cfi_remember_state
        .cfi_restore 30
        .cfi_restore 29
        .cfi_def_cfa_offset 0
        ret
.L8:
        .cfi_restore_state
        bl      abort
        .cfi_endproc

and now, we get:

f:
.LFB0:
        .cfi_startproc
        stp     x29, x30, [sp, -80]!
        .cfi_def_cfa_offset 80
        .cfi_offset 29, -80
        .cfi_offset 30, -72
        mov     w0, -32
        add     x1, sp, 80
        mov     x29, sp
        stp     x1, x1, [sp, 16]
        str     x1, [sp, 32]
        stp     wzr, w0, [sp, 40]
        str     q0, [sp, 48]
        str     q1, [sp, 64]
        bl      abort
        .cfi_endproc

which appears to unconditionally call abort().


More information about the Gcc-bugs mailing list