[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.
This commit is contained in:
Tomas Lindquist Olsen
2008-06-14 17:28:13 +02:00
parent d85267ef5a
commit c2430c713b
5 changed files with 31 additions and 15 deletions

View File

@@ -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

View File

@@ -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;
}

View File

@@ -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

View File

@@ -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)
{

View File

@@ -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)