From c2430c713bcde5110688de31adb4cb798ac801f8 Mon Sep 17 00:00:00 2001 From: Tomas Lindquist Olsen Date: Sat, 14 Jun 2008 17:28:13 +0200 Subject: [PATCH] [svn r285] Fixed D -> bool LLVM helper for floating point values. Changed the way D-style varargs are passed, now each param should be aligned to size_t.sizeof. --- gen/toir.cpp | 7 ++++++- gen/tollvm.cpp | 10 ++++++---- tango/tango/core/Vararg.d | 11 +++++++---- tango/tango/text/convert/Layout.d | 9 +++++++++ tangotests/vararg3.d | 9 +++------ 5 files changed, 31 insertions(+), 15 deletions(-) diff --git a/gen/toir.cpp b/gen/toir.cpp index 8761d5a1..c5b8442b 100644 --- a/gen/toir.cpp +++ b/gen/toir.cpp @@ -1121,6 +1121,9 @@ DValue* CallExp::toElem(IRState* p) Argument* argu = Argument::getNth(tf->parameters, i); Expression* argexp = (Expression*)arguments->data[i]; vtypes.push_back(DtoType(argexp->type)); + size_t sz = getABITypeSize(vtypes.back()); + if (sz < PTRSIZE) + vtypes.back() = DtoSize_t(); } const LLStructType* vtype = LLStructType::get(vtypes); Logger::cout() << "d-variadic argument struct type:\n" << *vtype << '\n'; @@ -1132,7 +1135,9 @@ DValue* CallExp::toElem(IRState* p) Expression* argexp = (Expression*)arguments->data[i]; if (global.params.llvmAnnotate) DtoAnnotation(argexp->toChars()); - DtoVariadicArgument(argexp, DtoGEPi(mem,0,k,"tmp")); + LLValue* argdst = DtoGEPi(mem,0,k); + argdst = DtoBitCast(argdst, getPtrToType(DtoType(argexp->type))); + DtoVariadicArgument(argexp, argdst); } // build type info array diff --git a/gen/tollvm.cpp b/gen/tollvm.cpp index a7eb8de0..e5a7b6eb 100644 --- a/gen/tollvm.cpp +++ b/gen/tollvm.cpp @@ -330,14 +330,16 @@ LLValue* DtoBoolean(LLValue* val) return new llvm::ICmpInst(llvm::ICmpInst::ICMP_NE, val, zero, "tmp", gIR->scopebb()); } } + else if (t->isFloatingPoint()) + { + LLValue* zero = llvm::Constant::getNullValue(t); + return new llvm::FCmpInst(llvm::FCmpInst::FCMP_ONE, val, zero, "tmp", gIR->scopebb()); + } else if (isaPointer(t)) { LLValue* zero = llvm::Constant::getNullValue(t); return new llvm::ICmpInst(llvm::ICmpInst::ICMP_NE, val, zero, "tmp", gIR->scopebb()); } - else - { - Logger::cout() << *t << '\n'; - } + std::cout << "unsupported -> bool : " << *t << '\n'; assert(0); return 0; } diff --git a/tango/tango/core/Vararg.d b/tango/tango/core/Vararg.d index bb038340..47c7ebdc 100644 --- a/tango/tango/core/Vararg.d +++ b/tango/tango/core/Vararg.d @@ -36,10 +36,13 @@ else version( LLVMDC ) */ T va_arg(T)(ref va_list vp) { - size_t size = T.sizeof > size_t.sizeof ? size_t.sizeof : T.sizeof; - va_list vptmp = cast(va_list)((cast(size_t)vp + size - 1) & ~(size - 1)); - vp = vptmp + T.sizeof; - return *cast(T*)vptmp; +// size_t size = T.sizeof > size_t.sizeof ? size_t.sizeof : T.sizeof; +// va_list vptmp = cast(va_list)((cast(size_t)vp + size - 1) & ~(size - 1)); +// vp = vptmp + T.sizeof; +// return *cast(T*)vptmp; + T* arg = cast(T*) vp; + vp = cast(va_list) ( cast(void*) vp + ( ( T.sizeof + size_t.sizeof - 1 ) & ~( size_t.sizeof - 1 ) ) ); + return *arg; } } else diff --git a/tango/tango/text/convert/Layout.d b/tango/tango/text/convert/Layout.d index 6f784501..a2efb337 100644 --- a/tango/tango/text/convert/Layout.d +++ b/tango/tango/text/convert/Layout.d @@ -195,6 +195,14 @@ class Layout(T) version (LLVMDC) { + // code for LLVMDC, all targets! + Arg[64] arglist = void; + foreach (i, arg; arguments) + { + arglist[i] = args; + args += (arg.tsize + size_t.sizeof - 1) & ~ (size_t.sizeof - 1); + } + /* static va_list get_va_arg(TypeInfo ti, ref va_list vp) { auto tisize = ti.tsize; @@ -209,6 +217,7 @@ class Layout(T) { arglist[i] = get_va_arg(arg, args); } + */ } else version (X86_64) { diff --git a/tangotests/vararg3.d b/tangotests/vararg3.d index 7823330a..747c1551 100644 --- a/tangotests/vararg3.d +++ b/tangotests/vararg3.d @@ -113,12 +113,9 @@ void main() private void* get_va_arg(TypeInfo ti, ref void* vp) { - auto tisize = ti.tsize; - assert(tisize); - size_t size = tisize > size_t.sizeof ? size_t.sizeof : tisize; - void* vptmp = cast(void*)((cast(size_t)vp + size - 1) & ~(size - 1)); - vp = vptmp + tisize; - return vptmp; + void* arg = vp; + vp = vp + ( ( ti.tsize + size_t.sizeof - 1 ) & ~( size_t.sizeof - 1 ) ); + return arg; } void print(TypeInfo ti, void* arg)