Re: [PATCH 1/7] Fix function argument and return value locations

Hannes Domani
2020-05-25T21:32:15Z

Am Montag, 25. Mai 2020, 23:02:37 MESZ hat Simon Marchi <simark@simark.ca> Folgendes geschrieben:

> On 2020-05-25 2:56 p.m., Hannes Domani via Gdb-patches wrote:
>
> > diff --git a/gdb/amd64-windows-tdep.c b/gdb/amd64-windows-tdep.c
> > index 487dfd45fc..db9845203f 100644
> > --- a/gdb/amd64-windows-tdep.c
> > +++ b/gdb/amd64-windows-tdep.c
> > @@ -77,7 +77,8 @@ static int
> >  amd64_windows_passed_by_xmm_register (struct type *type)
> >  {
> >    return ((type->code () == TYPE_CODE_FLT
> > -      || type->code () == TYPE_CODE_DECFLOAT)
> > +      || type->code () == TYPE_CODE_DECFLOAT
> > +      || type->code () == TYPE_CODE_COMPLEX)
> >            && (TYPE_LENGTH (type) == 4 || TYPE_LENGTH (type) == 8));
>
> >  }
>
> I don't know much about ABIs, so I tried:
>
> $ cat hello.c
> #include <complex.h>
>
> void other(int real, int imag);
> void func (complex int n)
> {
>   other(creal(n), cimag(n));
> }
> $ x86_64-w64-mingw32-gcc hello.c -g3 -O0 -c
> $ x86_64-w64-mingw32-objdump -d allo.o
>
> allo.o:    file format elf64-x86-64
>
>
> Disassembly of section .text:
>
> 0000000000000000 <func>:
>   0:  55                      push  %rbp
>   1:  48 89 e5                mov    %rsp,%rbp
>   4:  48 83 ec 10            sub    $0x10,%rsp
>   8:  48 89 7d f8            mov    %rdi,-0x8(%rbp)
>   c:  8b 45 fc                mov    -0x4(%rbp),%eax
>   f:  66 0f ef c0            pxor  %xmm0,%xmm0
>   13:  f2 0f 2a c0            cvtsi2sd %eax,%xmm0
>   17:  f2 0f 2c d0            cvttsd2si %xmm0,%edx
>   1b:  8b 45 f8                mov    -0x8(%rbp),%eax
>   1e:  66 0f ef c0            pxor  %xmm0,%xmm0
>   22:  f2 0f 2a c0            cvtsi2sd %eax,%xmm0
>   26:  f2 0f 2c c0            cvttsd2si %xmm0,%eax
>   2a:  89 d6                  mov    %edx,%esi
>   2c:  89 c7                  mov    %eax,%edi
>   2e:  e8 00 00 00 00          callq  33 <func+0x33>
>   33:  90                      nop
>   34:  c9                      leaveq
>   35:  c3                      retq
>
>
> Doesn't this show that a `complex int` argument is passed through the rdi
> register?  Am I missing something here?

You're probably right, the thing is, I was only able to test complex float
and complex double, because gdb doesn't like complex integral types:

complex int complex_int = 5 + 6i;

(gdb) p complex_int
'complex_int' has unknown type; cast it to its declared type
(gdb) pt complex_int
'complex_int' has unknown type; cast it to its declared type

So I guess it should check for target-type float as well:
|| (type->code () == TYPE_CODE_COMPLEX
&& TYPE_TARGET_TYPE (type)->code () == TYPE_CODE_FLT))

Do many people use complex int, because I personally wouldn't have expected
that this even exists.

Hannes