From 8da0d673cf0ae4231381aa418153cbad0abf751f Mon Sep 17 00:00:00 2001 From: Alexey Prokhin Date: Sat, 30 Apr 2011 15:30:57 +0400 Subject: [PATCH] Rework vaarg support on X86_64 --- gen/toir.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/gen/toir.cpp b/gen/toir.cpp index a5a99e24..d4022439 100644 --- a/gen/toir.cpp +++ b/gen/toir.cpp @@ -884,6 +884,11 @@ DValue* CallExp::toElem(IRState* p) if (LLValue *argptr = gIR->func()->_argptr) { DtoStore(DtoLoad(argptr), DtoBitCast(arg, getPtrToType(getVoidPtrType()))); return new DImValue(type, arg); + } else if (global.params.cpu == ARCHx86_64) { + LLValue *va_list = DtoAlloca(exp->type->nextOf()); + DtoStore(va_list, arg); + va_list = DtoBitCast(va_list, getVoidPtrType()); + return new DImValue(type, gIR->ir->CreateCall(GET_INTRINSIC_DECL(vastart), va_list, "")); } else #endif { @@ -891,6 +896,20 @@ DValue* CallExp::toElem(IRState* p) return new DImValue(type, gIR->ir->CreateCall(GET_INTRINSIC_DECL(vastart), arg, "")); } } +#if DMDV2 + else if (fndecl->llvmInternal == LLVMva_copy && global.params.cpu == ARCHx86_64) { + Expression* exp1 = (Expression*)arguments->data[0]; + Expression* exp2 = (Expression*)arguments->data[1]; + LLValue* arg1 = exp1->toElem(p)->getLVal(); + LLValue* arg2 = exp2->toElem(p)->getLVal(); + + LLValue *va_list = DtoAlloca(exp1->type->nextOf()); + DtoStore(va_list, arg1); + + DtoStore(DtoLoad(DtoLoad(arg2)), DtoLoad(arg1)); + return new DVarValue(type, arg1); + } +#endif // va_arg instruction else if (fndecl->llvmInternal == LLVMva_arg) { return DtoVaArg(loc, type, (Expression*)arguments->data[0]);