Merge branch 'master' into merge-2.068

Conflicts:
	dmd2/root/man.c
	tests/d2/dmd-testsuite
This commit is contained in:
Martin 2015-10-05 22:56:36 +02:00
commit cda8a12112
18 changed files with 90 additions and 107 deletions

View file

@ -651,7 +651,7 @@ longdouble Port::strtold(const char *p, char **endp)
#endif #endif
#if __linux__ || __APPLE__ || __FreeBSD__ || __OpenBSD__ || __HAIKU__ #if __linux__ || __APPLE__ || __FreeBSD__ || __OpenBSD__ || __DragonFly__ || __HAIKU__
#include <math.h> #include <math.h>
#if __linux__ #if __linux__
@ -806,7 +806,7 @@ int Port::isNan(double r)
#else #else
return __inline_isnan(r); return __inline_isnan(r);
#endif #endif
#elif __HAIKU__ || __FreeBSD__ || __OpenBSD__ #elif __HAIKU__ || __FreeBSD__ || __OpenBSD__ || __DragonFly__
return isnan(r); return isnan(r);
#else #else
#undef isnan #undef isnan
@ -822,7 +822,7 @@ int Port::isNan(longdouble r)
#else #else
return __inline_isnan(r); return __inline_isnan(r);
#endif #endif
#elif __HAIKU__ || __FreeBSD__ || __OpenBSD__ #elif __HAIKU__ || __FreeBSD__ || __OpenBSD__ || __DragonFly__
return isnan(r); return isnan(r);
#else #else
#undef isnan #undef isnan
@ -850,7 +850,7 @@ int Port::isInfinity(double r)
{ {
#if __APPLE__ #if __APPLE__
return fpclassify(r) == FP_INFINITE; return fpclassify(r) == FP_INFINITE;
#elif __HAIKU__ || __FreeBSD__ || __OpenBSD__ #elif __HAIKU__ || __FreeBSD__ || __OpenBSD__ || __DragonFly__
return isinf(r); return isinf(r);
#else #else
#undef isinf #undef isinf
@ -865,7 +865,7 @@ longdouble Port::sqrt(longdouble x)
longdouble Port::fmodl(longdouble x, longdouble y) longdouble Port::fmodl(longdouble x, longdouble y)
{ {
#if __FreeBSD__ && __FreeBSD_version < 800000 || __OpenBSD__ #if __FreeBSD__ && __FreeBSD_version < 800000 || __OpenBSD__ || __DragonFly__
return ::fmod(x, y); // hack for now, fix later return ::fmod(x, y); // hack for now, fix later
#else #else
return ::fmodl(x, y); return ::fmodl(x, y);

View file

@ -66,7 +66,7 @@ DValue* DtoAAIndex(Loc& loc, Type* type, DValue* aa, DValue* key, bool lvalue)
} }
// cast return value // cast return value
LLType* targettype = getPtrToType(i1ToI8(DtoType(type))); LLType* targettype = DtoPtrToType(type);
if (ret->getType() != targettype) if (ret->getType() != targettype)
ret = DtoBitCast(ret, targettype); ret = DtoBitCast(ret, targettype);

View file

@ -226,7 +226,7 @@ struct ExplicitByvalRewrite : ABIRewrite
LLType* type(Type* dty, LLType* t) LLType* type(Type* dty, LLType* t)
{ {
return getPtrToType(DtoType(dty)); return DtoPtrToType(dty);
} }
}; };

View file

@ -207,7 +207,7 @@ struct ImplicitByvalRewrite : ABIRewrite {
} }
LLType* type(Type* dty, LLType* t) { LLType* type(Type* dty, LLType* t) {
return getPtrToType(DtoType(dty)); return DtoPtrToType(dty);
} }
}; };

View file

@ -47,7 +47,7 @@ static LLValue *DtoSlice(LLValue *ptr, LLValue *length, LLType *elemType = NULL)
{ {
if (elemType == NULL) if (elemType == NULL)
elemType = ptr->getType()->getContainedType(0); elemType = ptr->getType()->getContainedType(0);
elemType = voidToI8(elemType); elemType = i1ToI8(voidToI8(elemType));
LLStructType *type = DtoArrayType(elemType); LLStructType *type = DtoArrayType(elemType);
LLValue *array = DtoRawAlloca(type, 0, ".array"); LLValue *array = DtoRawAlloca(type, 0, ".array");
@ -80,15 +80,13 @@ static LLValue *DtoSlicePtr(DValue *dval)
LLStructType* DtoArrayType(Type* arrayTy) LLStructType* DtoArrayType(Type* arrayTy)
{ {
assert(arrayTy->nextOf()); assert(arrayTy->nextOf());
LLType* elemty = i1ToI8(voidToI8(DtoType(arrayTy->nextOf()))); llvm::Type* elems[] = { DtoSize_t(), DtoPtrToType(arrayTy->nextOf()) };
llvm::Type *elems[] = { DtoSize_t(), getPtrToType(elemty) };
return llvm::StructType::get(gIR->context(), elems, false); return llvm::StructType::get(gIR->context(), elems, false);
} }
LLStructType* DtoArrayType(LLType* t) LLStructType* DtoArrayType(LLType* t)
{ {
llvm::Type *elems[] = { DtoSize_t(), getPtrToType(t) }; llvm::Type* elems[] = { DtoSize_t(), getPtrToType(t) };
return llvm::StructType::get(gIR->context(), elems, false); return llvm::StructType::get(gIR->context(), elems, false);
} }
@ -101,8 +99,7 @@ LLArrayType* DtoStaticArrayType(Type* t)
TypeSArray* tsa = static_cast<TypeSArray*>(t); TypeSArray* tsa = static_cast<TypeSArray*>(t);
Type* tnext = tsa->nextOf(); Type* tnext = tsa->nextOf();
LLType* elemty = i1ToI8(voidToI8(DtoType(tnext))); return LLArrayType::get(DtoMemType(tnext), tsa->dim->toUInteger());
return LLArrayType::get(elemty, tsa->dim->toUInteger());
} }
////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////
@ -170,9 +167,6 @@ static void DtoArrayInit(Loc& loc, LLValue* ptr, LLValue* length, DValue* dvalue
gIR->scope() = IRScope(bodybb); gIR->scope() = IRScope(bodybb);
LLValue* itr_val = DtoLoad(itr); LLValue* itr_val = DtoLoad(itr);
/* bitcopy element
//DtoMemCpy(DtoGEP1(ptr, itr_val), dvalue->getLVal(), elementSize);
*/
// assign array element value // assign array element value
DValue *arrayelem = new DVarValue(dvalue->type->toBasetype(), DtoGEP1(ptr, itr_val, "arrayinit.arrayelem")); DValue *arrayelem = new DVarValue(dvalue->type->toBasetype(), DtoGEP1(ptr, itr_val, "arrayinit.arrayelem"));
DtoAssign(loc, arrayelem, dvalue, op); DtoAssign(loc, arrayelem, dvalue, op);
@ -277,7 +271,7 @@ void DtoArrayAssign(Loc& loc, DValue* lhs, DValue* rhs, int op, bool canSkipPost
if (!needsDestruction && !needsPostblit) if (!needsDestruction && !needsPostblit)
{ {
// fast version // fast version
LLValue* elemSize = DtoConstSize_t(getTypePaddedSize(voidToI8(DtoType(elemType)))); LLValue* elemSize = DtoConstSize_t(getTypePaddedSize(DtoMemType(elemType)));
LLValue* lhsSize = gIR->ir->CreateMul(elemSize, lhsLength); LLValue* lhsSize = gIR->ir->CreateMul(elemSize, lhsLength);
if (rhs->isNull()) if (rhs->isNull())
@ -328,7 +322,7 @@ void DtoArrayAssign(Loc& loc, DValue* lhs, DValue* rhs, int op, bool canSkipPost
// fast version // fast version
LLValue* elemSize = DtoConstSize_t(getTypePaddedSize(realLhsPtr->getType()->getContainedType(0))); LLValue* elemSize = DtoConstSize_t(getTypePaddedSize(realLhsPtr->getType()->getContainedType(0)));
LLValue* lhsSize = gIR->ir->CreateMul(elemSize, lhsLength); LLValue* lhsSize = gIR->ir->CreateMul(elemSize, lhsLength);
LLType* rhsType = i1ToI8(voidToI8(DtoType(t2))); LLType* rhsType = DtoMemType(t2);
LLValue* rhsSize = DtoConstSize_t(getTypePaddedSize(rhsType)); LLValue* rhsSize = DtoConstSize_t(getTypePaddedSize(rhsType));
LLValue* actualPtr = DtoBitCast(lhsPtr, rhsType->getPointerTo()); LLValue* actualPtr = DtoBitCast(lhsPtr, rhsType->getPointerTo());
LLValue* actualLength = gIR->ir->CreateExactUDiv(lhsSize, rhsSize); LLValue* actualLength = gIR->ir->CreateExactUDiv(lhsSize, rhsSize);
@ -397,7 +391,7 @@ LLConstant* DtoConstArrayInitializer(ArrayInitializer* arrinit, Type* targetType
elemty = static_cast<TypeVector *>(arrty)->elementType(); elemty = static_cast<TypeVector *>(arrty)->elementType();
else else
elemty = arrty->nextOf(); elemty = arrty->nextOf();
LLType* llelemty = i1ToI8(voidToI8(DtoType(elemty))); LLType* llelemty = DtoMemType(elemty);
// true if array elements differ in type, can happen with array of unions // true if array elements differ in type, can happen with array of unions
bool mismatch = false; bool mismatch = false;
@ -547,7 +541,7 @@ llvm::Constant* arrayLiteralToConst(IRState* p, ArrayLiteralExp* ale)
if (!elementType) if (!elementType)
{ {
assert(ale->elements->dim == 0); assert(ale->elements->dim == 0);
elementType = i1ToI8(voidToI8(DtoType(ale->type->toBasetype()->nextOf()))); elementType = DtoMemType(ale->type->toBasetype()->nextOf());
return llvm::ConstantArray::get(LLArrayType::get(elementType, 0), vals); return llvm::ConstantArray::get(LLArrayType::get(elementType, 0), vals);
} }
@ -1063,22 +1057,32 @@ LLValue* DtoArrayPtr(DValue* v)
LOG_SCOPE; LOG_SCOPE;
Type* t = v->getType()->toBasetype(); Type* t = v->getType()->toBasetype();
if (t->ty == Tarray) { // v's LL array element type may not be the real one
// due to implicit casts (e.g., to base class)
LLType* wantedLLPtrType = DtoPtrToType(t->nextOf());
LLValue* ptr = NULL;
if (t->ty == Tarray)
{
if (DSliceValue* s = v->isSlice()) if (DSliceValue* s = v->isSlice())
return s->ptr; ptr = s->ptr;
else if (v->isNull()) else if (v->isNull())
return getNullPtr(getPtrToType(i1ToI8(DtoType(t->nextOf())))); ptr = getNullPtr(wantedLLPtrType);
else if (v->isLVal()) else if (v->isLVal())
return DtoLoad(DtoGEPi(v->getLVal(), 0,1), ".ptr"); ptr = DtoLoad(DtoGEPi(v->getLVal(), 0, 1), ".ptr");
return gIR->ir->CreateExtractValue(v->getRVal(), 1, ".ptr"); else
ptr = gIR->ir->CreateExtractValue(v->getRVal(), 1, ".ptr");
} }
else if (t->ty == Tsarray) { else if (t->ty == Tsarray)
{
assert(!v->isSlice()); assert(!v->isSlice());
assert(!v->isNull()); assert(!v->isNull());
return DtoGEPi(v->getRVal(), 0, 0, "sarrayptr"); ptr = DtoGEPi(v->getRVal(), 0, 0, "sarrayptr");
} }
else
llvm_unreachable("Unexpected array type.");
llvm_unreachable("Unexpected array type."); return DtoBitCast(ptr, wantedLLPtrType);
} }
////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////
@ -1112,7 +1116,7 @@ DValue* DtoCastArray(Loc& loc, DValue* u, Type* to)
IF_LOG Logger::cout() << "to array" << '\n'; IF_LOG Logger::cout() << "to array" << '\n';
LLType* ptrty = DtoArrayType(totype)->getContainedType(1); LLType* ptrty = DtoArrayType(totype)->getContainedType(1);
LLType* ety = voidToI8(DtoType(fromtype->nextOf())); LLType* ety = DtoMemType(fromtype->nextOf());
if (fromtype->ty == Tsarray) { if (fromtype->ty == Tsarray) {
LLValue* uval = u->getRVal(); LLValue* uval = u->getRVal();

View file

@ -72,7 +72,7 @@ LLValue* DtoNew(Loc& loc, Type* newtype)
// call runtime allocator // call runtime allocator
LLValue* mem = gIR->CreateCallOrInvoke(fn, ti, ".gc_mem").getInstruction(); LLValue* mem = gIR->CreateCallOrInvoke(fn, ti, ".gc_mem").getInstruction();
// cast // cast
return DtoBitCast(mem, getPtrToType(i1ToI8(DtoType(newtype))), ".gc_mem"); return DtoBitCast(mem, DtoPtrToType(newtype), ".gc_mem");
} }
LLValue* DtoNewStruct(Loc& loc, TypeStruct* newtype) LLValue* DtoNewStruct(Loc& loc, TypeStruct* newtype)
@ -81,7 +81,7 @@ LLValue* DtoNewStruct(Loc& loc, TypeStruct* newtype)
newtype->isZeroInit(newtype->sym->loc) ? "_d_newitemT" : "_d_newitemiT"); newtype->isZeroInit(newtype->sym->loc) ? "_d_newitemT" : "_d_newitemiT");
LLConstant* ti = DtoTypeInfoOf(newtype); LLConstant* ti = DtoTypeInfoOf(newtype);
LLValue* mem = gIR->CreateCallOrInvoke(fn, ti, ".gc_struct").getInstruction(); LLValue* mem = gIR->CreateCallOrInvoke(fn, ti, ".gc_struct").getInstruction();
return DtoBitCast(mem, getPtrToType(i1ToI8(DtoType(newtype))), ".gc_struct"); return DtoBitCast(mem, DtoPtrToType(newtype), ".gc_struct");
} }
void DtoDeleteMemory(Loc& loc, DValue* ptr) void DtoDeleteMemory(Loc& loc, DValue* ptr)
@ -141,8 +141,7 @@ void DtoDeleteArray(Loc& loc, DValue* arr)
llvm::AllocaInst* DtoAlloca(Type* type, const char* name) llvm::AllocaInst* DtoAlloca(Type* type, const char* name)
{ {
LLType* lltype = i1ToI8(DtoType(type)); return DtoRawAlloca(DtoMemType(type), type->alignsize(), name);
return DtoRawAlloca(lltype, type->alignsize(), name);
} }
llvm::AllocaInst* DtoArrayAlloca(Type* type, unsigned arraysize, const char* name) llvm::AllocaInst* DtoArrayAlloca(Type* type, unsigned arraysize, const char* name)
@ -201,8 +200,8 @@ LLValue* DtoAllocaDump(LLValue* val, Type* asType, const char* name)
LLValue* DtoAllocaDump(LLValue* val, LLType* asType, int alignment, const char* name) LLValue* DtoAllocaDump(LLValue* val, LLType* asType, int alignment, const char* name)
{ {
LLType* valType = i1ToI8(val->getType()); LLType* valType = i1ToI8(voidToI8(val->getType()));
asType = i1ToI8(asType); asType = i1ToI8(voidToI8(asType));
LLType* allocaType = ( LLType* allocaType = (
getTypeStoreSize(valType) <= getTypeAllocSize(asType) ? asType : valType); getTypeStoreSize(valType) <= getTypeAllocSize(asType) ? asType : valType);
LLValue* mem = DtoRawAlloca(allocaType, alignment, name); LLValue* mem = DtoRawAlloca(allocaType, alignment, name);
@ -391,7 +390,7 @@ DValue* DtoNullValue(Type* type, Loc loc)
else if (basety == Tarray) else if (basety == Tarray)
{ {
LLValue* len = DtoConstSize_t(0); LLValue* len = DtoConstSize_t(0);
LLValue* ptr = getNullPtr(getPtrToType(DtoType(basetype->nextOf()))); LLValue* ptr = getNullPtr(DtoPtrToType(basetype->nextOf()));
return new DSliceValue(type, len, ptr); return new DSliceValue(type, len, ptr);
} }
else else
@ -727,7 +726,7 @@ DValue* DtoPaintType(Loc& loc, DValue* val, Type* to)
{ {
LLValue* ptr = val->getLVal(); LLValue* ptr = val->getLVal();
assert(isaPointer(ptr)); assert(isaPointer(ptr));
ptr = DtoBitCast(ptr, getPtrToType(DtoType(dgty))); ptr = DtoBitCast(ptr, DtoPtrToType(dgty));
IF_LOG Logger::cout() << "dg ptr: " << *ptr << '\n'; IF_LOG Logger::cout() << "dg ptr: " << *ptr << '\n';
return new DVarValue(to, ptr); return new DVarValue(to, ptr);
} }
@ -866,7 +865,7 @@ void DtoResolveVariable(VarDeclaration* vd)
} }
llvm::GlobalVariable* gvar = getOrCreateGlobal(vd->loc, gIR->module, llvm::GlobalVariable* gvar = getOrCreateGlobal(vd->loc, gIR->module,
i1ToI8(DtoType(vd->type)), isLLConst, linkage, 0, llName, DtoMemType(vd->type), isLLConst, linkage, 0, llName,
vd->isThreadlocal()); vd->isThreadlocal());
getIrGlobal(vd)->value = gvar; getIrGlobal(vd)->value = gvar;
@ -1183,7 +1182,7 @@ LLConstant* DtoConstInitializer(Loc& loc, Type* type, Initializer* init)
else if (init->isVoidInitializer()) else if (init->isVoidInitializer())
{ {
Logger::println("const void initializer"); Logger::println("const void initializer");
LLType* ty = voidToI8(DtoType(type)); LLType* ty = DtoMemType(type);
_init = LLConstant::getNullValue(ty); _init = LLConstant::getNullValue(ty);
} }
else else
@ -1225,7 +1224,7 @@ LLConstant* DtoConstExpInit(Loc& loc, Type* targetType, Expression* exp)
} }
llvm::Type* llType = val->getType(); llvm::Type* llType = val->getType();
llvm::Type* targetLLType = i1ToI8(DtoType(targetBase)); llvm::Type* targetLLType = DtoMemType(targetBase);
if (llType == targetLLType) if (llType == targetLLType)
{ {
Logger::println("Matching LLVM types, ignoring frontend glitch."); Logger::println("Matching LLVM types, ignoring frontend glitch.");
@ -1653,7 +1652,7 @@ DValue* DtoSymbolAddress(Loc& loc, Type* type, Declaration* decl)
if (isGlobal) if (isGlobal)
{ {
llvm::Type* expectedType = llvm::PointerType::getUnqual(i1ToI8(DtoType(type))); llvm::Type* expectedType = llvm::PointerType::getUnqual(DtoMemType(type));
// The type of globals is determined by their initializer, so // The type of globals is determined by their initializer, so
// we might need to cast. Make sure that the type sizes fit - // we might need to cast. Make sure that the type sizes fit -
// '==' instead of '<=' should probably work as well. // '==' instead of '<=' should probably work as well.
@ -1841,7 +1840,7 @@ LLValue* DtoIndexAggregate(LLValue* src, AggregateDeclaration* ad, VarDeclaratio
} }
// Cast the (possibly void*) pointer to the canonical variable type. // Cast the (possibly void*) pointer to the canonical variable type.
val = DtoBitCast(val, getPtrToType(i1ToI8(DtoType(vd->type)))); val = DtoBitCast(val, DtoPtrToType(vd->type));
IF_LOG Logger::cout() << "Value: " << *val << '\n'; IF_LOG Logger::cout() << "Value: " << *val << '\n';
return val; return val;

View file

@ -424,8 +424,7 @@ static void build_dso_ctor_dtor_body(
static void build_module_ref(std::string moduleMangle, llvm::Constant* thisModuleInfo) static void build_module_ref(std::string moduleMangle, llvm::Constant* thisModuleInfo)
{ {
// Build the ModuleInfo reference and bracketing symbols. // Build the ModuleInfo reference and bracketing symbols.
llvm::Type* const moduleInfoPtrTy = llvm::Type* const moduleInfoPtrTy = DtoPtrToType(Module::moduleinfo->type);
getPtrToType(DtoType(Module::moduleinfo->type));
std::string thismrefname = "_D"; std::string thismrefname = "_D";
thismrefname += moduleMangle; thismrefname += moduleMangle;
@ -445,8 +444,7 @@ static void build_module_ref(std::string moduleMangle, llvm::Constant* thisModul
static void build_dso_registry_calls(std::string moduleMangle, llvm::Constant* thisModuleInfo) static void build_dso_registry_calls(std::string moduleMangle, llvm::Constant* thisModuleInfo)
{ {
// Build the ModuleInfo reference and bracketing symbols. // Build the ModuleInfo reference and bracketing symbols.
llvm::Type* const moduleInfoPtrTy = llvm::Type* const moduleInfoPtrTy = DtoPtrToType(Module::moduleinfo->type);
getPtrToType(DtoType(Module::moduleinfo->type));
// Order is important here: We must create the symbols in the // Order is important here: We must create the symbols in the
// bracketing sections right before/after the ModuleInfo reference // bracketing sections right before/after the ModuleInfo reference
@ -789,8 +787,7 @@ static void genModuleInfo(Module *m, bool emitFullModuleInfo)
RTTIBuilder b(Module::moduleinfo); RTTIBuilder b(Module::moduleinfo);
// some types // some types
llvm::Type* const moduleInfoPtrTy = llvm::Type* const moduleInfoPtrTy = DtoPtrToType(Module::moduleinfo->type);
getPtrToType(DtoType(Module::moduleinfo->type));
LLType* classinfoTy = Type::typeinfoclass->type->ctype->getLLType(); LLType* classinfoTy = Type::typeinfoclass->type->ctype->getLLType();
// importedModules[] // importedModules[]

View file

@ -64,7 +64,7 @@ DValue* DtoNestedVariable(Loc& loc, Type* astype, VarDeclaration* vd, bool byref
while (fd != vdparent) { while (fd != vdparent) {
if (fd->isStatic()) { if (fd->isStatic()) {
error(loc, "function %s cannot access frame of function %s", irfunc->decl->toPrettyChars(), vdparent->toPrettyChars()); error(loc, "function %s cannot access frame of function %s", irfunc->decl->toPrettyChars(), vdparent->toPrettyChars());
return new DVarValue(astype, vd, llvm::UndefValue::get(getPtrToType(DtoType(astype)))); return new DVarValue(astype, vd, llvm::UndefValue::get(DtoPtrToType(astype)));
} }
fd = getParentFunc(fd, false); fd = getParentFunc(fd, false);
assert(fd); assert(fd);
@ -406,14 +406,14 @@ static void DtoCreateNestedContextType(FuncDeclaration* fd) {
if (lazy) if (lazy)
types.push_back(irparam->value->getType()->getContainedType(0)); types.push_back(irparam->value->getType()->getContainedType(0));
else else
types.push_back(i1ToI8(DtoType(vd->type))); types.push_back(DtoMemType(vd->type));
} else { } else {
types.push_back(irparam->value->getType()); types.push_back(irparam->value->getType());
} }
} else if (isSpecialRefVar(vd)) { } else if (isSpecialRefVar(vd)) {
types.push_back(DtoType(vd->type->pointerTo())); types.push_back(DtoType(vd->type->pointerTo()));
} else { } else {
types.push_back(i1ToI8(DtoType(vd->type))); types.push_back(DtoMemType(vd->type));
} }
IF_LOG Logger::cout() << "Nested var '" << vd->toChars() IF_LOG Logger::cout() << "Nested var '" << vd->toChars()
<< "' of type " << *types.back() << "\n"; << "' of type " << *types.back() << "\n";

View file

@ -176,7 +176,7 @@ public:
bool nullterm = (t->ty != Tsarray); bool nullterm = (t->ty != Tsarray);
size_t endlen = nullterm ? e->len+1 : e->len; size_t endlen = nullterm ? e->len+1 : e->len;
LLType* ct = voidToI8(DtoType(cty)); LLType* ct = DtoMemType(cty);
LLArrayType* at = LLArrayType::get(ct,endlen); LLArrayType* at = LLArrayType::get(ct,endlen);
llvm::StringMap<llvm::GlobalVariable*>* stringLiteralCache = 0; llvm::StringMap<llvm::GlobalVariable*>* stringLiteralCache = 0;
@ -572,7 +572,7 @@ public:
Type* elemt = bt->nextOf(); Type* elemt = bt->nextOf();
// build llvm array type // build llvm array type
LLArrayType* arrtype = LLArrayType::get(i1ToI8(voidToI8(DtoType(elemt))), e->elements->dim); LLArrayType* arrtype = LLArrayType::get(DtoMemType(elemt), e->elements->dim);
// dynamic arrays can occur here as well ... // dynamic arrays can occur here as well ...
bool dyn = (bt->ty != Tsarray); bool dyn = (bt->ty != Tsarray);

View file

@ -430,7 +430,7 @@ public:
Type* dtype = e->type->toBasetype(); Type* dtype = e->type->toBasetype();
Type* cty = dtype->nextOf()->toBasetype(); Type* cty = dtype->nextOf()->toBasetype();
LLType* ct = voidToI8(DtoType(cty)); LLType* ct = DtoMemType(cty);
LLArrayType* at = LLArrayType::get(ct, e->len+1); LLArrayType* at = LLArrayType::get(ct, e->len+1);
llvm::StringMap<llvm::GlobalVariable*>* stringLiteralCache = 0; llvm::StringMap<llvm::GlobalVariable*>* stringLiteralCache = 0;
@ -1004,7 +1004,7 @@ public:
// handle cast to void (usually created by frontend to avoid "has no effect" error) // handle cast to void (usually created by frontend to avoid "has no effect" error)
if (e->to == Type::tvoid) { if (e->to == Type::tvoid) {
result = new DImValue(Type::tvoid, llvm::UndefValue::get(voidToI8(DtoType(Type::tvoid)))); result = new DImValue(Type::tvoid, llvm::UndefValue::get(DtoMemType(Type::tvoid)));
return; return;
} }
@ -2367,7 +2367,7 @@ public:
if (retPtr) if (retPtr)
result = new DVarValue(e->type, DtoLoad(retPtr)); result = new DVarValue(e->type, DtoLoad(retPtr));
else else
result = new DConstValue(e->type, getNullValue(voidToI8(DtoType(dtype)))); result = new DConstValue(e->type, getNullValue(DtoMemType(dtype)));
} }
////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////
@ -2445,7 +2445,7 @@ public:
DtoAppendDCharToUnicodeString(e->loc, result, e->e2); DtoAppendDCharToUnicodeString(e->loc, result, e->e2);
} }
else if (e1type->equals(e2type)) { else if (e1type->equals(e2type)) {
// apeend array // append array
DSliceValue* slice = DtoCatAssignArray(e->loc, result, e->e2); DSliceValue* slice = DtoCatAssignArray(e->loc, result, e->e2);
DtoAssign(e->loc, result, slice); DtoAssign(e->loc, result, slice);
} }
@ -2554,7 +2554,7 @@ public:
IF_LOG Logger::cout() << (dyn?"dynamic":"static") << " array literal with length " << len << " of D type: '" << arrayType->toChars() << "' has llvm type: '" << *llType << "'\n"; IF_LOG Logger::cout() << (dyn?"dynamic":"static") << " array literal with length " << len << " of D type: '" << arrayType->toChars() << "' has llvm type: '" << *llType << "'\n";
// llvm storage type // llvm storage type
LLType* llElemType = i1ToI8(voidToI8(DtoType(elemType))); LLType* llElemType = DtoMemType(elemType);
LLType* llStoType = LLArrayType::get(llElemType, len); LLType* llStoType = LLArrayType::get(llElemType, len);
IF_LOG Logger::cout() << "llvm storage type: '" << *llStoType << "'\n"; IF_LOG Logger::cout() << "llvm storage type: '" << *llStoType << "'\n";
@ -2824,7 +2824,7 @@ public:
// (&a.foo).funcptr is a case where toElem(e1) is genuinely not an l-value. // (&a.foo).funcptr is a case where toElem(e1) is genuinely not an l-value.
LLValue* val = makeLValue(exp->loc, toElem(exp->e1)); LLValue* val = makeLValue(exp->loc, toElem(exp->e1));
LLValue* v = DtoGEPi(val, 0, index); LLValue* v = DtoGEPi(val, 0, index);
return new DVarValue(exp->type, DtoBitCast(v, getPtrToType(DtoType(exp->type)))); return new DVarValue(exp->type, DtoBitCast(v, DtoPtrToType(exp->type)));
} }
void visit(DelegatePtrExp *e) void visit(DelegatePtrExp *e)
@ -2888,7 +2888,7 @@ public:
types.reserve(e->exps->dim); types.reserve(e->exps->dim);
for (size_t i = 0; i < e->exps->dim; i++) for (size_t i = 0; i < e->exps->dim; i++)
{ {
types.push_back(i1ToI8(voidToI8(DtoType((*e->exps)[i]->type)))); types.push_back(DtoMemType((*e->exps)[i]->type));
} }
LLValue *val = DtoRawAlloca(LLStructType::get(gIR->context(), types), 0, ".tuple"); LLValue *val = DtoRawAlloca(LLStructType::get(gIR->context(), types), 0, ".tuple");
for (size_t i = 0; i < e->exps->dim; i++) for (size_t i = 0; i < e->exps->dim; i++)

View file

@ -202,44 +202,21 @@ LLType* DtoType(Type* t)
return IrTypeVector::get(t)->getLLType(); return IrTypeVector::get(t)->getLLType();
} }
/*
Not needed atm as VarDecls for tuples are rewritten as a string of
VarDecls for the fields (u -> _u_field_0, ...)
case Ttuple:
{
TypeTuple* ttupl = static_cast<TypeTuple*>(t);
return DtoStructTypeFromArguments(ttupl->arguments);
}
*/
default: default:
llvm_unreachable("Unknown class of D Type!"); llvm_unreachable("Unknown class of D Type!");
} }
return 0; return 0;
} }
////////////////////////////////////////////////////////////////////////////////////////// LLType* DtoMemType(Type* t)
/*
LLType* DtoStructTypeFromArguments(Arguments* arguments)
{ {
if (!arguments) return i1ToI8(voidToI8(DtoType(t)));
return LLType::getVoidTy(gIR->context());
std::vector<LLType*> types;
for (size_t i = 0; i < arguments->dim; i++)
{
Argument *arg = (*arguments)[i];
assert(arg && arg->type);
types.push_back(DtoType(arg->type));
}
return LLStructType::get(types);
} }
*/
////////////////////////////////////////////////////////////////////////////////////////// LLPointerType* DtoPtrToType(Type* t)
{
return DtoMemType(t)->getPointerTo();
}
LLType* voidToI8(LLType* t) LLType* voidToI8(LLType* t)
{ {
@ -248,8 +225,6 @@ LLType* voidToI8(LLType* t)
return t; return t;
} }
//////////////////////////////////////////////////////////////////////////////////////////
LLType* i1ToI8(LLType* t) LLType* i1ToI8(LLType* t)
{ {
if (t == LLType::getInt1Ty(gIR->context())) if (t == LLType::getInt1Ty(gIR->context()))

View file

@ -32,6 +32,11 @@
* DtoTypeFunction(FuncDeclaration*) is to be used instead. * DtoTypeFunction(FuncDeclaration*) is to be used instead.
*/ */
LLType* DtoType(Type* t); LLType* DtoType(Type* t);
// Uses DtoType(), but promotes i1 and void to i8.
LLType* DtoMemType(Type* t);
// Returns a pointer to the type returned by DtoMemType(t).
LLPointerType* DtoPtrToType(Type* t);
LLType* voidToI8(LLType* t); LLType* voidToI8(LLType* t);
LLType* i1ToI8(LLType* t); LLType* i1ToI8(LLType* t);

View file

@ -132,7 +132,7 @@ LLConstant* get_default_initializer(VarDeclaration* vd, Initializer* init)
{ {
// We need to be able to handle void[0] struct members even if void has // We need to be able to handle void[0] struct members even if void has
// no default initializer. // no default initializer.
return llvm::ConstantPointerNull::get(getPtrToType(DtoType(vd->type))); return llvm::ConstantPointerNull::get(DtoPtrToType(vd->type));
} }
return DtoConstExpInit(vd->loc, vd->type, vd->type->defaultInit(vd->loc)); return DtoConstExpInit(vd->loc, vd->type, vd->type->defaultInit(vd->loc));
} }
@ -173,11 +173,14 @@ llvm::Constant* IrAggr::createInitializerConstant(
{ {
// add vtbl // add vtbl
constants.push_back(getVtblSymbol()); constants.push_back(getVtblSymbol());
// add monitor offset += Target::ptrsize;
constants.push_back(getNullValue(DtoType(Type::tvoid->pointerTo())));
// we start right after the vtbl and monitor // add monitor (except for C++ classes)
offset = Target::ptrsize * 2; if (!aggrdecl->isClassDeclaration()->isCPPclass())
{
constants.push_back(getNullValue(getVoidPtrType()));
offset += Target::ptrsize;
}
} }
// Add the initializers for the member fields. While we are traversing the // Add the initializers for the member fields. While we are traversing the

View file

@ -174,7 +174,7 @@ IrTypePointer* IrTypePointer::get(Type* dt)
} }
else else
{ {
elemType = i1ToI8(voidToI8(DtoType(dt->nextOf()))); elemType = DtoMemType(dt->nextOf());
// DtoType could have already created the same type, e.g. for // DtoType could have already created the same type, e.g. for
// dt == Node* in struct Node { Node* n; }. // dt == Node* in struct Node { Node* n; }.
@ -212,7 +212,7 @@ llvm::Type * IrTypeSArray::sarray2llvm(Type * t)
assert(t->ty == Tsarray && "not static array type"); assert(t->ty == Tsarray && "not static array type");
TypeSArray* tsa = static_cast<TypeSArray*>(t); TypeSArray* tsa = static_cast<TypeSArray*>(t);
uint64_t dim = static_cast<uint64_t>(tsa->dim->toUInteger()); uint64_t dim = static_cast<uint64_t>(tsa->dim->toUInteger());
LLType* elemType = i1ToI8(voidToI8(DtoType(t->nextOf()))); LLType* elemType = DtoMemType(t->nextOf());
return llvm::ArrayType::get(elemType, dim); return llvm::ArrayType::get(elemType, dim);
} }
@ -232,7 +232,7 @@ IrTypeArray* IrTypeArray::get(Type* dt)
assert(!dt->ctype); assert(!dt->ctype);
assert(dt->ty == Tarray && "not dynamic array type"); assert(dt->ty == Tarray && "not dynamic array type");
LLType* elemType = i1ToI8(voidToI8(DtoType(dt->nextOf()))); LLType* elemType = DtoMemType(dt->nextOf());
// Could have already built the type as part of a struct forward reference, // Could have already built the type as part of a struct forward reference,
// just as for pointers. // just as for pointers.
@ -273,7 +273,7 @@ llvm::Type* IrTypeVector::vector2llvm(Type* dt)
assert(tv->basetype->ty == Tsarray); assert(tv->basetype->ty == Tsarray);
TypeSArray* tsa = static_cast<TypeSArray*>(tv->basetype); TypeSArray* tsa = static_cast<TypeSArray*>(tv->basetype);
uint64_t dim = static_cast<uint64_t>(tsa->dim->toUInteger()); uint64_t dim = static_cast<uint64_t>(tsa->dim->toUInteger());
LLType* elemType = voidToI8(DtoType(tsa->next)); LLType* elemType = DtoMemType(tsa->next);
return llvm::VectorType::get(elemType, dim); return llvm::VectorType::get(elemType, dim);
} }

View file

@ -179,7 +179,7 @@ void AggrTypeBuilder::addAggregate(AggregateDeclaration *ad)
} }
// add default type // add default type
m_defaultTypes.push_back(i1ToI8(DtoType(vd->type))); m_defaultTypes.push_back(DtoMemType(vd->type));
// advance offset to right past this field // advance offset to right past this field
m_offset += getMemberSize(vd->type); m_offset += getMemberSize(vd->type);

View file

@ -25,13 +25,13 @@ IrTypeFunction::IrTypeFunction(Type* dt, llvm::Type* lt, const IrFuncTy& irFty_)
{ {
} }
IrTypeFunction* IrTypeFunction::get(Type* dt, Type* nestedContextOverride) IrTypeFunction* IrTypeFunction::get(Type* dt)
{ {
assert(!dt->ctype); assert(!dt->ctype);
assert(dt->ty == Tfunction); assert(dt->ty == Tfunction);
IrFuncTy irFty; IrFuncTy irFty;
llvm::Type* lt = DtoFunctionType(dt, irFty, NULL, nestedContextOverride); llvm::Type* lt = DtoFunctionType(dt, irFty, NULL, NULL);
IrTypeFunction* result = new IrTypeFunction(dt, lt, irFty); IrTypeFunction* result = new IrTypeFunction(dt, lt, irFty);
dt->ctype = result; dt->ctype = result;

View file

@ -23,7 +23,7 @@ class IrTypeFunction : public IrType
{ {
public: public:
/// ///
static IrTypeFunction* get(Type* dt, Type* nestedContextOverride = 0); static IrTypeFunction* get(Type* dt);
/// ///
IrTypeFunction* isFunction() { return this; } IrTypeFunction* isFunction() { return this; }

@ -1 +1 @@
Subproject commit 3b5d5648b2ec0c6f0548425610a10d15bbcc00af Subproject commit 35376ace10dc885360ff63d82c790aaf35097bc1