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...)