public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/96527] New: __builtin_va_arg_pack_len produces error in documented sample code
@ 2020-08-07 16:42 bruno at clisp dot org
  2020-08-07 17:07 ` [Bug c/96527] " jakub at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: bruno at clisp dot org @ 2020-08-07 16:42 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 96527
           Summary: __builtin_va_arg_pack_len produces error in documented
                    sample code
           Product: gcc
           Version: 10.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: bruno at clisp dot org
  Target Milestone: ---

Created attachment 49024
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=49024&action=edit
Test case

The only documented example of __builtin_va_arg_pack_len, in
https://gcc.gnu.org/onlinedocs/gcc-10.2.0/gcc/Constructing-Calls.html ,
produces an error "invalid use of '__builtin_va_arg_pack_len ()'" when actually
used.

Test case foo.c is attached. GCC 5.5.0, 6.5.0, 7.5.0, 8.4.0, 9.3.0, 10.2.0 all
produce an error:

$ gcc -O2 -Wall -S foo.c
foo.c: In function 'myopen':
foo.c:7:7: error: invalid use of '__builtin_va_arg_pack_len ()'
    7 |   if (__builtin_va_arg_pack_len () > 1)
      |       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~

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

* [Bug c/96527] __builtin_va_arg_pack_len produces error in documented sample code
  2020-08-07 16:42 [Bug c/96527] New: __builtin_va_arg_pack_len produces error in documented sample code bruno at clisp dot org
@ 2020-08-07 17:07 ` jakub at gcc dot gnu.org
  2020-08-07 19:39 ` bruno at clisp dot org
  2020-08-07 19:47 ` jakub at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-08-07 17:07 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
                 CC|                            |jakub at gcc dot gnu.org
         Resolution|---                         |INVALID

--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
The error is correct.  __builtin_va_arg_pack_len or __builtin_va_arg_pack can't
work in functions that are not inlined.
And the documentation you refer to is clear about it for both:
"It can be used only in inline functions that are always inlined, never
compiled as a separate function, such as those using __attribute__
((__always_inline__)) or __attribute__ ((__gnu_inline__)) extern inline
functions."
So, either you need to compile with -fgnu-inline, or have the gnu_inline
attribute on it if it is extern inline, or it must be only inline and not
extern inline for the standard C.
extern inline __attribute__ ((__gnu_inline__)) is the mode it was designed for,
if it can be inline, you use something that accesses the ... arguments,
otherwise either you have a guarantee it will never be called out of line, or
there is some external definition which will not use these builtins and will
handle ... normally through va_{list,start,arg,end}.

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

* [Bug c/96527] __builtin_va_arg_pack_len produces error in documented sample code
  2020-08-07 16:42 [Bug c/96527] New: __builtin_va_arg_pack_len produces error in documented sample code bruno at clisp dot org
  2020-08-07 17:07 ` [Bug c/96527] " jakub at gcc dot gnu.org
@ 2020-08-07 19:39 ` bruno at clisp dot org
  2020-08-07 19:47 ` jakub at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: bruno at clisp dot org @ 2020-08-07 19:39 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Bruno Haible <bruno at clisp dot org> ---
Created attachment 49026
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=49026&action=edit
Corrected test case

I see. A corrected test case is attached.

I wanted to avoid __gnu_inline__ because that's an attribute that is known to
have caused trouble with GCC 4.2.x / 4.3.x. Nowadays, the preferred attribute
is 'inline' from ISO C11. And I got in trouble with the 'extern' modifier while
doing that...

How about changing the example in the documentation to use
static inline __attribute__((__always_inline__))
instead of
extern inline __attribute__((__gnu_inline__))
?

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

* [Bug c/96527] __builtin_va_arg_pack_len produces error in documented sample code
  2020-08-07 16:42 [Bug c/96527] New: __builtin_va_arg_pack_len produces error in documented sample code bruno at clisp dot org
  2020-08-07 17:07 ` [Bug c/96527] " jakub at gcc dot gnu.org
  2020-08-07 19:39 ` bruno at clisp dot org
@ 2020-08-07 19:47 ` jakub at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-08-07 19:47 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
The extern inline __attribute__((__gnu_inline__)) usecase comes from actual
code (e.g. glibc) where it is used this way a lot, I'm not aware of anybody
using static inline __attribute__((__always_inline__)) together with these.

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

end of thread, other threads:[~2020-08-07 19:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-07 16:42 [Bug c/96527] New: __builtin_va_arg_pack_len produces error in documented sample code bruno at clisp dot org
2020-08-07 17:07 ` [Bug c/96527] " jakub at gcc dot gnu.org
2020-08-07 19:39 ` bruno at clisp dot org
2020-08-07 19:47 ` jakub 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).