public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug objc/101718] New: Objective-C frontend emits wrong code to call methods returning _Complex types returned in memory
@ 2021-08-02  6:03 mhjacobson at me dot com
  2021-08-07 20:16 ` [Bug objc/101718] Objective-C frontend emits wrong code to call methods returning scalar " iains at gcc dot gnu.org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: mhjacobson at me dot com @ 2021-08-02  6:03 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 101718
           Summary: Objective-C frontend emits wrong code to call methods
                    returning _Complex types returned in memory
           Product: gcc
           Version: 10.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: objc
          Assignee: unassigned at gcc dot gnu.org
          Reporter: mhjacobson at me dot com
  Target Milestone: ---

When a method returns a type that the platform ABI says is returned in memory,
the Objective-C frontend (for the NeXT runtime ABIs) emits a call to
`objc_msgSend_stret`; the `_stret` variant of the message dispatcher knows to
look at the *second* argument for `self`, and so on, since the first argument
is the pointer to where the return value will go.

On some platforms, `_Complex double` is too large to be returned through
registers, so it's returned through memory.

But the Objective-C frontend still insists on using `objc_msgSend`, not
`objc_msgSend_stret`.

`objc_msgSend` is thoroughly confused when the first argument, which it expects
to be `self`, is actually a pointer to garbage-filled stack.

I believe this happens because this check:

```
  /* If we are returning a struct in memory, and the address
     of that memory location is passed as a hidden first
     argument, then change which messenger entry point this
     expr will call.  NB: Note that sender_cast remains
     unchanged (it already has a struct return type).  */
  if (!targetm.calls.struct_value_rtx (0, 0)
      && (TREE_CODE (ret_type) == RECORD_TYPE
          || TREE_CODE (ret_type) == UNION_TYPE)
      && targetm.calls.return_in_memory (ret_type, 0))
    {
```

limits the use of `stret` to record/union types.  Primitive types that are
returned in memory should also be made to use `stret` (the name's meaning
notwithstanding).

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

end of thread, other threads:[~2024-03-31  7:53 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-02  6:03 [Bug objc/101718] New: Objective-C frontend emits wrong code to call methods returning _Complex types returned in memory mhjacobson at me dot com
2021-08-07 20:16 ` [Bug objc/101718] Objective-C frontend emits wrong code to call methods returning scalar " iains at gcc dot gnu.org
2021-08-11  1:35 ` mhjacobson at me dot com
2021-08-16 20:08 ` iains at gcc dot gnu.org
2021-08-16 20:18 ` iains at gcc dot gnu.org
2021-09-01 14:23 ` cvs-commit at gcc dot gnu.org
2022-05-31 18:32 ` cvs-commit at gcc dot gnu.org
2022-05-31 18:34 ` iains at gcc dot gnu.org
2024-03-31  7:52 ` cvs-commit at gcc dot gnu.org
2024-03-31  7:53 ` iains 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).