public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/107729] New: unhelpful handling for PMF on Itanium ABI for inline asm
@ 2022-11-16 22:23 compnerd at compnerd dot org
  2022-11-16 22:27 ` [Bug c++/107729] " pinskia at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: compnerd at compnerd dot org @ 2022-11-16 22:23 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 107729
           Summary: unhelpful handling for PMF on Itanium ABI for inline
                    asm
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: compnerd at compnerd dot org
  Target Milestone: ---

It seems that the GCC handling for inline assembly with PMF references seems to
generate something would possibly work but is not entirely helpful in all
cases.  The correctness of the code is most-definitely questionable at the very
least, if not flat out invalid.

Consider the following:
```c++
template <typename F_>
void f() {
  decltype(&F_::operator()) p;
  __asm__ __volatile__("__compnerd_was_here__" : [output] "=r" (p) : [input]
"r" (&F_::operator()));
}

auto L = [](){};
template void f<decltype(L)>();
```

When built with (x86_64) `-momit-leaf-frame-pointer -std=c++11 -g0
-fno-exceptions -fno-unwind-tables` the interesting (undecorated) output is:

```asm
void f<L::{lambda()#1}>():
.LFB4:
        movl    $L::{lambda()#1}::operator()() const, %eax    ; note truncation
of `ptr`
        movl    $0, %edx                                      ; note truncation
of `adj`
        __compnerd_was_here__
        movq    %rax, -24(%rsp)                               ; `ptr``
        movq    %rdx, -16(%rsp)                               ; `adj`
        nop
        ret
.LFE4:
```

Adding in `-fpic` is slightly helpful as it _does_ happen to avoid the pointer
truncation:

```asm
void f<L::{lambda()#1}>():
.LFB4:
        movq    L::{lambda()#1}::operator()() const@GOTPCREL(%rip), %rcx  ;
note not-truncated `ptr`
        movq    %rcx, %rax                                                ; eh?
        movl    $0, %edx                                                  ;
untruncated `adj`
        __compnerd_was_here__
        movq    %rax, -24(%rsp)                                           ;
`ptr`
        movq    %rdx, -16(%rsp)                                           ;
`adj`
        nop
        ret
.LFE4:
```

The secondary one seems nearly correct, however, at that point a secondary
issue is exposed: the register allocation is irretrievable - your parameters
are `%0` and `%1` (or `%[input]` and `%[output]`.  The inability to destructure
the input and output as well as being unable to name the register pair makes
this rather unhelpful.

In the particular case, the PMF is a lambda without captures and thus is
reasonable as the adjustment is `0` and thus will happen to work.

There is a secondary question of the code quality itself - `r` as a constraint
for a PMF is unreasonable as per the ABI.  I don't think that there is a good
reason to permit that in the first place, but definitely not with the inability
to de-structure the parameters.

it is interesting to also note that GCC somehow does manage to de-structure and
re-structure the PMF, which is shockingly impressive.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/107729] unhelpful handling for PMF on Itanium ABI for inline asm
  2022-11-16 22:23 [Bug c++/107729] New: unhelpful handling for PMF on Itanium ABI for inline asm compnerd at compnerd dot org
@ 2022-11-16 22:27 ` pinskia at gcc dot gnu.org
  2022-11-16 22:28 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-11-16 22:27 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
<source>:6:1: warning: unsupported size for integer register

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/107729] unhelpful handling for PMF on Itanium ABI for inline asm
  2022-11-16 22:23 [Bug c++/107729] New: unhelpful handling for PMF on Itanium ABI for inline asm compnerd at compnerd dot org
  2022-11-16 22:27 ` [Bug c++/107729] " pinskia at gcc dot gnu.org
@ 2022-11-16 22:28 ` pinskia at gcc dot gnu.org
  2022-11-16 22:31 ` compnerd at compnerd dot org
  2022-11-16 22:33 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-11-16 22:28 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #1)
> <source>:6:1: warning: unsupported size for integer register

I get that when I use:
#%0 %1

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/107729] unhelpful handling for PMF on Itanium ABI for inline asm
  2022-11-16 22:23 [Bug c++/107729] New: unhelpful handling for PMF on Itanium ABI for inline asm compnerd at compnerd dot org
  2022-11-16 22:27 ` [Bug c++/107729] " pinskia at gcc dot gnu.org
  2022-11-16 22:28 ` pinskia at gcc dot gnu.org
@ 2022-11-16 22:31 ` compnerd at compnerd dot org
  2022-11-16 22:33 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: compnerd at compnerd dot org @ 2022-11-16 22:31 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Saleem Abdulrasool <compnerd at compnerd dot org> ---
(In reply to Andrew Pinski from comment #2)
> (In reply to Andrew Pinski from comment #1)
> > <source>:6:1: warning: unsupported size for integer register
> 
> I get that when I use:
> #%0 %1

This totally makes sense - the value is a pointer pair, so it does detect that
will overflow.  IMO that is a positive and hopefully will deter people from
doing this in practice at least.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/107729] unhelpful handling for PMF on Itanium ABI for inline asm
  2022-11-16 22:23 [Bug c++/107729] New: unhelpful handling for PMF on Itanium ABI for inline asm compnerd at compnerd dot org
                   ` (2 preceding siblings ...)
  2022-11-16 22:31 ` compnerd at compnerd dot org
@ 2022-11-16 22:33 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-11-16 22:33 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |WONTFIX
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
GCC does have an extension to do something you want already I think:
https://gcc.gnu.org/onlinedocs/gcc-12.2.0/gcc/Bound-member-functions.html#Bound-member-functions

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-11-16 22:33 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-16 22:23 [Bug c++/107729] New: unhelpful handling for PMF on Itanium ABI for inline asm compnerd at compnerd dot org
2022-11-16 22:27 ` [Bug c++/107729] " pinskia at gcc dot gnu.org
2022-11-16 22:28 ` pinskia at gcc dot gnu.org
2022-11-16 22:31 ` compnerd at compnerd dot org
2022-11-16 22:33 ` pinskia at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).