[cfe-dev] Question on VisitVAArgExpr()

Eli Friedman eli.friedman at gmail.com
Wed Feb 10 11:36:43 PST 2010


On Wed, Feb 10, 2010 at 10:56 AM, Sylvere Teissier <st at invia.fr> wrote:
> Hi,
> If we look at the 3 different implementations of VisitVAArgExpr function
> in clang source...:
>
> --------------------------------------------------------------------
> Value *ScalarExprEmitter::VisitVAArgExpr(VAArgExpr *VE) {
>  llvm::Value *ArgValue = CGF.EmitVAListRef(VE->getSubExpr());
>  llvm::Value *ArgPtr = CGF.EmitVAArg(ArgValue, VE->getType());
>
>  // If EmitVAArg fails, we fall back to the LLVM instruction.
>  if (!ArgPtr)
>    return Builder.CreateVAArg(ArgValue, ConvertType(VE->getType()));
>
>  // FIXME Volatility.
>  return Builder.CreateLoad(ArgPtr);
> }
> ----------------------------------------------------------------------
> ComplexPairTy ComplexExprEmitter::VisitVAArgExpr(VAArgExpr *E) {
>  llvm::Value *ArgValue = CGF.EmitVAListRef(E->getSubExpr());
>  llvm::Value *ArgPtr = CGF.EmitVAArg(ArgValue, E->getType());
>
>  if (!ArgPtr) {
>    CGF.ErrorUnsupported(E, "complex va_arg expression");
>    const llvm::Type *EltTy =
>      CGF.ConvertType(E->getType()->getAs<ComplexType>()->getElementType());
>    llvm::Value *U = llvm::UndefValue::get(EltTy);
>    return ComplexPairTy(U, U);
>  }
>
>  // FIXME Volatility.
>  return EmitLoadOfComplex(ArgPtr, false);
> }
> -----------------------------------------------------------------------
> void AggExprEmitter::VisitVAArgExpr(VAArgExpr *VE) {
>  llvm::Value *ArgValue = CGF.EmitVAListRef(VE->getSubExpr());
>  llvm::Value *ArgPtr = CGF.EmitVAArg(ArgValue, VE->getType());
>
>  if (!ArgPtr) {
>    CGF.ErrorUnsupported(VE, "aggregate va_arg expression");
>    return;
>  }
>
>  EmitFinalDestCopy(VE, LValue::MakeAddr(ArgPtr, Qualifiers()));
> }
> -----------------------------------------------------------------------
>
> ...there is no fall back to the LLVM va_arg instruction if (ArgPtr==0)
> for the aggregate and complex case
> Then there is an unsupported error for architectures that don't
> implement EmitVAArg...
>
> Why? Is it a bug or is it impossible to use LLVM va_arg instruction for
> these cases ?

The LLVM va_arg instruction isn't really well-supported generally...
it might work, but probably not, and it's not a well-tested codepath.
Your best option is adding an implementation at the clang level.

-Eli




More information about the cfe-dev mailing list