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

            Bug ID: 129107
           Summary: float field lost when passing a #pragma pack struct
                    with a misaligned double on sparc64
           Product: gcc
           Version: 16.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: stian at itx dot no
                CC: ebotcazou at gcc dot gnu.org, ro at gcc dot gnu.org,
                    sjames at gcc dot gnu.org
  Target Milestone: ---
            Target: sparc64-*-*

On sparc64, a struct with a double at a 4-byte offset loses its float member
when it is passed by value:

#include <stdio.h>

#pragma pack(push, 1)
struct K { float a; double b; };
#pragma pack(pop)

__attribute__ ((noipa)) void
f (struct K k)
{
  printf ("%g %g\n", k.a, k.b);
}

int
main (void)
{
  struct K k = { 1.25f, 81.5 };
  f (k);
  return 0;
}

$ gcc -O2 pr.c && ./a.out
3.31836 81.5

Expected "1.25 81.5". -O0 gives the same. 3.31836 is the high word of 81.5.

function_arg_record_value assigns both fields to %f0:

  (reg:SF 32 %f0 [ k ])
  (reg:DF 32 %f0 [ k+4 ])

assign_fp_registers only moves a field to the odd register when it is 4 bytes
or smaller. The double at bit 32 of the slot gets SPARC_FP_ARG_FIRST + slotno *
2, the same register as the float. The caller loads a into %f0 and then
overwrites it with b.

#pragma pack does not set DECL_PACKED, so traverse_record_type does not switch
to integer registers as it does for __attribute__ ((packed)).

12.2.0 and 16.2.0 on Compiler Explorer generate the same caller code. The code
is unchanged on master.

I found this while testing clang's SPARC64 argument passing against GCC for
https://github.com/llvm/llvm-project/pull/246226. clang passes a in %f0 and the
bytes of b in %o0 and %o1.

Reply via email to