bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

improve clang support (7)


From: Bruno Haible
Subject: improve clang support (7)
Date: Fri, 07 Aug 2020 18:34:25 +0200
User-agent: KMail/5.1.3 (Linux/4.4.0-186-generic; KDE/5.18.0; x86_64; ; )

clang (up to version 10.0) does not support __builtin_va_arg_pack and
__builtin_va_arg_pack_len: it complains about "use of unknown builtin".

We can leave this code in lib/cdefs.h

#if __GNUC_PREREQ (4,3)
# define __va_arg_pack() __builtin_va_arg_pack ()
# define __va_arg_pack_len() __builtin_va_arg_pack_len ()
#endif

as is (since clang pretends to be GCC 4.2.1 compatible on non-Windows
platforms). Or write
  #if __GNUC_PREREQ (4,3) || __has_attribute (__builtin_va_arg_pack)

I vote for leaving it as-is.

Bruno

============================== Test case ==========================
typedef struct FILE FILE;
extern int fprintf (FILE *, const char *format, ...);
extern int myprintf (FILE *f, const char *format, ...);
extern inline __attribute__ ((__gnu_inline__)) int
myprintf (FILE *f, const char *format, ...)
{
  int r = fprintf (f, "myprintf: %d", __builtin_va_arg_pack_len ());
  if (r < 0)
    return r;
  int s = fprintf (f, format, __builtin_va_arg_pack ());
  if (s < 0)
    return s;
  return r + s;
}
void foo (FILE *fp)
{
  myprintf (fp, "%s%s", "bar", "baz");
}

extern void warn_open_too_many_arguments (void);
extern void warn_open_missing_mode (void);
extern int open (const char *, int, ...);
extern int open_2 (const char *, int);
extern inline int myopen (const char *path, int oflag, ...)
{
  //if (__builtin_va_arg_pack_len () > 1)
  //  warn_open_too_many_arguments ();

  if (__builtin_constant_p (oflag))
    {
      if ((oflag & 4) != 0 && __builtin_va_arg_pack_len () < 1)
        {
          warn_open_missing_mode ();
          return open_2 (path, oflag);
        }
      return open (path, oflag, __builtin_va_arg_pack ());
    }

  if (__builtin_va_arg_pack_len () < 1)
    return open_2 (path, oflag);

  return open (path, oflag, __builtin_va_arg_pack ());
}
int rpl_open (const char *path, int oflag, ...)
{
  return myopen (path, 44, 23) + myopen (path, 36);
}
====================================================================



reply via email to

[Prev in Thread] Current Thread [Next in Thread]