public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/111307] New: RFE: builtin to construct va_list
@ 2023-09-06 14:48 equinox-gccbugs at diac24 dot net
  2023-09-12 11:12 ` [Bug c/111307] " rguenth at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: equinox-gccbugs at diac24 dot net @ 2023-09-06 14:48 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 111307
           Summary: RFE: builtin to construct va_list
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: equinox-gccbugs at diac24 dot net
  Target Milestone: ---

A common pattern of defining a pair of varargs functions looks like:

  void somefuncv(char *spec, va_list ap)
  {
      /* ... */
  }
  void somefunc(char *spec, ...)
  {
      va_list ap
      va_start(ap, spec);
      sumefuncv(spec, ap);
      va_end(ap);
  }

  somefunc("%d", 1234); /* => quite a bit of wasted moving bits around */

However, the resulting code for calling somefunc() is suboptimal; the arguments
are arranged as specified by the psABI, only to then be rearranged into a
va_list by somefunc (which can be rather complex since somefunc has no clue
about type, number, or even floating-point calling conventions of its
arguments.)

It would be very helpful if GCC added a builtin function to create a va_list
for a given "...", with a (pseudo-)prototype like "__builtin_va_list
__builtin_va_construct(...)".  This could be used to directly put together a
va_list at the caller's location, e.g.:

  #define somefunc(spec, ...) somefuncv(spec,
__builtin_va_construct(__VA_ARGS__))

  somefunc("%d", 1234); /* => minimal va_list to carry a single int */

Thus the round-trip through the psABI could be avoided, with the caller
constructing a minimal (since it knows all the args) va_list.

(This builtin would also make inlining varargs functions much less relevant,
since there are no more actual varargs functions in the latter example...)

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

* [Bug c/111307] RFE: builtin to construct va_list
  2023-09-06 14:48 [Bug c/111307] New: RFE: builtin to construct va_list equinox-gccbugs at diac24 dot net
@ 2023-09-12 11:12 ` rguenth at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-09-12 11:12 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Version|unknown                     |14.0
           Keywords|                            |missed-optimization

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
The problem at hand is really similar to the one inlining a varags function.

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

end of thread, other threads:[~2023-09-12 11:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-06 14:48 [Bug c/111307] New: RFE: builtin to construct va_list equinox-gccbugs at diac24 dot net
2023-09-12 11:12 ` [Bug c/111307] " rguenth 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).