From dbe4852b7b41758aa83c9c5a5a77ccd810bd08ea Mon Sep 17 00:00:00 2001 From: Tomas Lindquist Olsen Date: Sun, 10 May 2009 04:37:03 +0200 Subject: [PATCH] Fixed D-style vararg arguments with types that have sizes bigger that pointers, yet are not aligned to pointer sizes. Fixes ticket #276 . --- gen/tocall.cpp | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/gen/tocall.cpp b/gen/tocall.cpp index 241780a0..2e52a725 100644 --- a/gen/tocall.cpp +++ b/gen/tocall.cpp @@ -141,8 +141,28 @@ void DtoBuildDVarArgList(std::vector& args, std::vectortype->ty != Ttuple); vtypes.push_back(DtoType(argexp->type)); size_t sz = getTypePaddedSize(vtypes.back()); - if (sz < PTRSIZE) - vtypes.back() = DtoSize_t(); + size_t asz = (sz + PTRSIZE - 1) & ~(PTRSIZE -1); + if (sz != asz) + { + if (sz < PTRSIZE) + { + vtypes.back() = DtoSize_t(); + } + else + { + // ok then... so we build some type that is big enough + // and aligned to PTRSIZE + std::vector gah; + gah.reserve(asz/PTRSIZE); + size_t gah_sz = 0; + while (gah_sz < asz) + { + gah.push_back(DtoSize_t()); + gah_sz += PTRSIZE; + } + vtypes.back() = LLStructType::get(gah, true); + } + } } const LLStructType* vtype = LLStructType::get(vtypes);