mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-05-01 07:30:43 +03:00
Error instead of assert when trying to build a default initializer for void[n].
This commit is contained in:
parent
1b16f2234e
commit
049e24cef8
6 changed files with 20 additions and 15 deletions
|
@ -289,7 +289,7 @@ LLConstant* DtoConstArrayInitializer(ArrayInitializer* arrinit)
|
|||
}
|
||||
|
||||
if (!v)
|
||||
v = DtoConstInitializer(t->nextOf(), init);
|
||||
v = DtoConstInitializer(arrinit->loc, t->nextOf(), init);
|
||||
assert(v);
|
||||
|
||||
inits[i] = v;
|
||||
|
|
|
@ -491,7 +491,7 @@ void DtoConstInitClass(ClassDeclaration* cd)
|
|||
for (IrStruct::OffsetMap::iterator i=irstruct->offsets.begin(); i!=irstruct->offsets.end(); ++i)
|
||||
{
|
||||
IrStruct::Offset* so = &i->second;
|
||||
LLConstant* finit = DtoConstFieldInitializer(so->var->type, so->var->init);
|
||||
LLConstant* finit = DtoConstFieldInitializer(so->var->loc, so->var->type, so->var->init);
|
||||
so->init = finit;
|
||||
so->var->ir.irField->constInit = finit;
|
||||
}
|
||||
|
|
|
@ -971,11 +971,11 @@ void DtoConstInitGlobal(VarDeclaration* vd)
|
|||
|
||||
LLConstant* _init = 0;
|
||||
if (vd->parent && vd->parent->isFuncDeclaration() && vd->init && vd->init->isExpInitializer()) {
|
||||
_init = DtoConstInitializer(vd->type, NULL);
|
||||
_init = DtoConstInitializer(vd->loc, vd->type, NULL);
|
||||
emitRTstaticInit = true;
|
||||
}
|
||||
else {
|
||||
_init = DtoConstInitializer(vd->type, vd->init);
|
||||
_init = DtoConstInitializer(vd->loc, vd->type, vd->init);
|
||||
}
|
||||
|
||||
const LLType* _type = DtoType(vd->type);
|
||||
|
@ -1396,13 +1396,13 @@ LLValue* DtoRawVarDeclaration(VarDeclaration* var)
|
|||
// INITIALIZER HELPERS
|
||||
////////////////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
LLConstant* DtoConstInitializer(Type* type, Initializer* init)
|
||||
LLConstant* DtoConstInitializer(Loc& loc, Type* type, Initializer* init)
|
||||
{
|
||||
LLConstant* _init = 0; // may return zero
|
||||
if (!init)
|
||||
{
|
||||
Logger::println("const default initializer for %s", type->toChars());
|
||||
_init = DtoDefaultInit(type);
|
||||
_init = DtoDefaultInit(loc, type);
|
||||
}
|
||||
else if (ExpInitializer* ex = init->isExpInitializer())
|
||||
{
|
||||
|
@ -1433,14 +1433,14 @@ LLConstant* DtoConstInitializer(Type* type, Initializer* init)
|
|||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
LLConstant* DtoConstFieldInitializer(Type* t, Initializer* init)
|
||||
LLConstant* DtoConstFieldInitializer(Loc& loc, Type* t, Initializer* init)
|
||||
{
|
||||
Logger::println("DtoConstFieldInitializer");
|
||||
LOG_SCOPE;
|
||||
|
||||
const LLType* _type = DtoType(t);
|
||||
|
||||
LLConstant* _init = DtoConstInitializer(t, init);
|
||||
LLConstant* _init = DtoConstInitializer(loc, t, init);
|
||||
assert(_init);
|
||||
if (_type != _init->getType())
|
||||
{
|
||||
|
@ -1568,7 +1568,7 @@ static LLConstant* expand_to_sarray(Type *base, Expression* exp)
|
|||
return val;
|
||||
}
|
||||
|
||||
LLConstant* DtoDefaultInit(Type* type)
|
||||
LLConstant* DtoDefaultInit(Loc& loc, Type* type)
|
||||
{
|
||||
Expression* exp = type->defaultInit();
|
||||
|
||||
|
@ -1580,6 +1580,11 @@ LLConstant* DtoDefaultInit(Type* type)
|
|||
{
|
||||
if (base->ty == Tsarray)
|
||||
{
|
||||
if (base->nextOf()->toBasetype()->ty == Tvoid) {
|
||||
error(loc, "static arrays of voids have no default initializer");
|
||||
fatal();
|
||||
}
|
||||
|
||||
Logger::println("type is a static array, building constant array initializer to single value");
|
||||
return expand_to_sarray(base, exp);
|
||||
}
|
||||
|
|
|
@ -86,8 +86,8 @@ DValue* DtoDeclarationExp(Dsymbol* declaration);
|
|||
LLValue* DtoRawVarDeclaration(VarDeclaration* var);
|
||||
|
||||
// initializer helpers
|
||||
LLConstant* DtoConstInitializer(Type* type, Initializer* init);
|
||||
LLConstant* DtoConstFieldInitializer(Type* type, Initializer* init);
|
||||
LLConstant* DtoConstInitializer(Loc& loc, Type* type, Initializer* init);
|
||||
LLConstant* DtoConstFieldInitializer(Loc& loc, Type* type, Initializer* init);
|
||||
DValue* DtoInitializer(LLValue* target, Initializer* init);
|
||||
|
||||
// annotation generator
|
||||
|
@ -109,7 +109,7 @@ DValue* DtoBinRem(Type* resulttype, DValue* lhs, DValue* rhs);
|
|||
void findDefaultTarget();
|
||||
|
||||
/// get the default initializer of the type
|
||||
LLConstant* DtoDefaultInit(Type* t);
|
||||
LLConstant* DtoDefaultInit(Loc& loc, Type* t);
|
||||
|
||||
// fixup an overloaded intrinsic name string
|
||||
void DtoOverloadedIntrinsicName(TemplateInstance* ti, TemplateDeclaration* td, std::string& name);
|
||||
|
|
|
@ -42,7 +42,7 @@ LLConstant* DtoConstStructInitializer(StructInitializer* si)
|
|||
assert(ini);
|
||||
VarDeclaration* vd = (VarDeclaration*)si->vars.data[i];
|
||||
assert(vd);
|
||||
LLConstant* v = DtoConstInitializer(vd->type, ini);
|
||||
LLConstant* v = DtoConstInitializer(vd->loc, vd->type, ini);
|
||||
inits.push_back(DUnionIdx(vd->ir.irField->index, vd->ir.irField->indexOffset, v));
|
||||
}
|
||||
|
||||
|
@ -290,7 +290,7 @@ void DtoConstInitStruct(StructDeclaration* sd)
|
|||
for (IrStruct::OffsetMap::iterator i=irstruct->offsets.begin(); i!=irstruct->offsets.end(); ++i)
|
||||
{
|
||||
IrStruct::Offset* so = &i->second;
|
||||
LLConstant* finit = DtoConstFieldInitializer(so->var->type, so->var->init);
|
||||
LLConstant* finit = DtoConstFieldInitializer(so->var->loc, so->var->type, so->var->init);
|
||||
so->init = finit;
|
||||
so->var->ir.irField->constInit = finit;
|
||||
}
|
||||
|
|
|
@ -424,7 +424,7 @@ void TypeInfoTypedefDeclaration::llvmDefine()
|
|||
}
|
||||
else
|
||||
{
|
||||
LLConstant* ci = DtoConstInitializer(sd->basetype, sd->init);
|
||||
LLConstant* ci = DtoConstInitializer(sd->loc, sd->basetype, sd->init);
|
||||
std::string ciname(sd->mangle());
|
||||
ciname.append("__init");
|
||||
llvm::GlobalVariable* civar = new llvm::GlobalVariable(DtoType(sd->basetype),true,llvm::GlobalValue::InternalLinkage,ci,ciname,gIR->module);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue