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

H.J. Lu <hjl.tools at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |hjl.tools at gmail dot 
com
   Last reconfirmed|                            |2020-04-09
             Status|UNCONFIRMED                 |ASSIGNED
      Known to work|                            |4.9.3
            Summary|-mx32 gcc produces wrong    |[8/9/10 Regression] -mx32
                   |code passing structs by     |gcc produces wrong code
                   |value                       |passing structs by value
     Ever confirmed|0                           |1

--- Comment #3 from H.J. Lu <hjl.tools at gmail dot com> ---
[hjl@gnu-cfl-2 tmp]$ cat bar.c
typedef unsigned int size_t;
struct Array
{
  size_t length;
  void *ptr;
};
extern int munmap (void *__addr, size_t __len);

int
deallocate(struct Array b)
{
  int result = 0;
  if (b.length)
    result = munmap(b.ptr, b.length);
  return result;
}
[hjl@gnu-cfl-2 tmp]$  gcc -S -O bar.c -mx32 
[hjl@gnu-cfl-2 tmp]$ cat bar.s
        .file   "bar.c"
        .text
        .globl  deallocate
        .type   deallocate, @function
deallocate:
.LFB0:
        .cfi_startproc
        movl    $0, %eax
        testl   %edi, %edi
        jne     .L8
        ret
.L8:
        subl    $8, %esp
        .cfi_def_cfa_offset 16
        movq    %rdi, %rsi   <<<<<< It should be movl %edi, %esi
        shrq    $32, %rdi
        call    munmap
        addl    $8, %esp
        .cfi_def_cfa_offset 8
        ret
        .cfi_endproc
.LFE0:
        .size   deallocate, .-deallocate
        .ident  "GCC: (GNU) 9.3.1 20200408 (Red Hat 9.3.1-2)"
        .section        .note.GNU-stack,"",@progbits
[hjl@gnu-cfl-2 tmp]$ 

GCC 4.9.3 works.

Reply via email to