[PATCH] missing va_end() in some IO functions (gmp 6.1.2)

Vincent Lefevre vincent at vinc17.net
Thu Mar 14 15:09:26 UTC 2019


On 2019-03-14 12:38:13 +0100, Torbjorn Granlund wrote:
> Is stdarg.h va_end non-empty anywhere?

Yes, with GCC and Clang, for instance. It is defined as:

#define va_end(v)       __builtin_va_end(v)

gcc/builtins.c contains:

static rtx
expand_builtin_va_end (tree exp)
{
  tree valist = CALL_EXPR_ARG (exp, 0);

  /* Evaluate for side effects, if needed.  I hate macros that don't
     do that.  */
  if (TREE_SIDE_EFFECTS (valist))
    expand_expr (valist, const0_rtx, VOIDmode, EXPAND_NORMAL);

  return const0_rtx;
}

So, if I understand correctly, it does nothing except than taking
care of side effects. However, since the C standard explicitly says
that va_end is a macro, I'm not sure that having arguments with
side effects is allowed. What GCC does is probably safer than
doing nothing (without any drawback), though.

This means that with GMP, __builtin_va_end(v) would expand to nothing.

BTW, I've just fixed a bug in tcc, which did

#define va_end(ap)

instead of

#define va_end(ap) ((void)0)

This matters when writing, e.g.: (va_end(ap));

-- 
Vincent Lefèvre <vincent at vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)


More information about the gmp-bugs mailing list