[llvm-dev] va_arg macro

Qiantan Hong via llvm-dev llvm-dev at lists.llvm.org
Thu Oct 4 15:22:01 PDT 2018


Hi,

New here, not mean to be spam. If I’m doing something wrong please just tell me.

I’ve found that clang v7 treats va_arg, at least differently from gcc (and c standard says it should accept argument with one void). Clang does not accept va_arg(…,void).
When I was trying to build redis I got this:

hiredis.c:799:31: error: second argument to 'va_arg' is of incomplete type
      'void'
                    va_arg(ap,void);

I then write a work around by replacing `#define va_arg(ap, type)    __builtin_va_arg(ap, type)` with those line to stdarg.h (In my environment, the path is /usr/local/Cellar/llvm/7.0.0/lib/clang/7.0.0/include):

#define __kscarlet_transform_cat_(x,y) x##y
#define __kscarlet_transform_cat(x,y) __kscarlet_transform_cat_(x,y)
#define __kscarlet_transform_void() )()__kscarlet_transform_n_(
#define __kscarlet_transform_e(...) __VA_ARGS__
#define __kscarlet_transform_e_(...) __VA_ARGS__
#define __kscarlet_transform_n(...)
#define __kscarlet_transform_n2(...) char
#define __kscarlet_transform_n_(...) __kscarlet_transform_n2
#define __kscarlet_transform_void_(...) __kscarlet_transform_e
#define va_arg(ap,type) __builtin_va_arg(ap,__kscarlet_transform_e_(__kscarlet_transform_void_ __kscarlet_transform_n()(__kscarlet_transform_cat( __kscarlet_transform_,type)()))(type))

This solves the problem, though it polluted global namespace. Do you have any idea to patch it / whether it should be patched?

Best,
BlueFlo0d



-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 1842 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20181004/781626cc/attachment.bin>


More information about the llvm-dev mailing list