mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-05-03 00:20:40 +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)
|
if (!v)
|
||||||
v = DtoConstInitializer(t->nextOf(), init);
|
v = DtoConstInitializer(arrinit->loc, t->nextOf(), init);
|
||||||
assert(v);
|
assert(v);
|
||||||
|
|
||||||
inits[i] = 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)
|
for (IrStruct::OffsetMap::iterator i=irstruct->offsets.begin(); i!=irstruct->offsets.end(); ++i)
|
||||||
{
|
{
|
||||||
IrStruct::Offset* so = &i->second;
|
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->init = finit;
|
||||||
so->var->ir.irField->constInit = finit;
|
so->var->ir.irField->constInit = finit;
|
||||||
}
|
}
|
||||||
|
|
|
@ -971,11 +971,11 @@ void DtoConstInitGlobal(VarDeclaration* vd)
|
||||||
|
|
||||||
LLConstant* _init = 0;
|
LLConstant* _init = 0;
|
||||||
if (vd->parent && vd->parent->isFuncDeclaration() && vd->init && vd->init->isExpInitializer()) {
|
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;
|
emitRTstaticInit = true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
_init = DtoConstInitializer(vd->type, vd->init);
|
_init = DtoConstInitializer(vd->loc, vd->type, vd->init);
|
||||||
}
|
}
|
||||||
|
|
||||||
const LLType* _type = DtoType(vd->type);
|
const LLType* _type = DtoType(vd->type);
|
||||||
|
@ -1396,13 +1396,13 @@ LLValue* DtoRawVarDeclaration(VarDeclaration* var)
|
||||||
// INITIALIZER HELPERS
|
// INITIALIZER HELPERS
|
||||||
////////////////////////////////////////////////////////////////////////////////////////*/
|
////////////////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
LLConstant* DtoConstInitializer(Type* type, Initializer* init)
|
LLConstant* DtoConstInitializer(Loc& loc, Type* type, Initializer* init)
|
||||||
{
|
{
|
||||||
LLConstant* _init = 0; // may return zero
|
LLConstant* _init = 0; // may return zero
|
||||||
if (!init)
|
if (!init)
|
||||||
{
|
{
|
||||||
Logger::println("const default initializer for %s", type->toChars());
|
Logger::println("const default initializer for %s", type->toChars());
|
||||||
_init = DtoDefaultInit(type);
|
_init = DtoDefaultInit(loc, type);
|
||||||
}
|
}
|
||||||
else if (ExpInitializer* ex = init->isExpInitializer())
|
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");
|
Logger::println("DtoConstFieldInitializer");
|
||||||
LOG_SCOPE;
|
LOG_SCOPE;
|
||||||
|
|
||||||
const LLType* _type = DtoType(t);
|
const LLType* _type = DtoType(t);
|
||||||
|
|
||||||
LLConstant* _init = DtoConstInitializer(t, init);
|
LLConstant* _init = DtoConstInitializer(loc, t, init);
|
||||||
assert(_init);
|
assert(_init);
|
||||||
if (_type != _init->getType())
|
if (_type != _init->getType())
|
||||||
{
|
{
|
||||||
|
@ -1568,7 +1568,7 @@ static LLConstant* expand_to_sarray(Type *base, Expression* exp)
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
LLConstant* DtoDefaultInit(Type* type)
|
LLConstant* DtoDefaultInit(Loc& loc, Type* type)
|
||||||
{
|
{
|
||||||
Expression* exp = type->defaultInit();
|
Expression* exp = type->defaultInit();
|
||||||
|
|
||||||
|
@ -1580,6 +1580,11 @@ LLConstant* DtoDefaultInit(Type* type)
|
||||||
{
|
{
|
||||||
if (base->ty == Tsarray)
|
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");
|
Logger::println("type is a static array, building constant array initializer to single value");
|
||||||
return expand_to_sarray(base, exp);
|
return expand_to_sarray(base, exp);
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,8 +86,8 @@ DValue* DtoDeclarationExp(Dsymbol* declaration);
|
||||||
LLValue* DtoRawVarDeclaration(VarDeclaration* var);
|
LLValue* DtoRawVarDeclaration(VarDeclaration* var);
|
||||||
|
|
||||||
// initializer helpers
|
// initializer helpers
|
||||||
LLConstant* DtoConstInitializer(Type* type, Initializer* init);
|
LLConstant* DtoConstInitializer(Loc& loc, Type* type, Initializer* init);
|
||||||
LLConstant* DtoConstFieldInitializer(Type* type, Initializer* init);
|
LLConstant* DtoConstFieldInitializer(Loc& loc, Type* type, Initializer* init);
|
||||||
DValue* DtoInitializer(LLValue* target, Initializer* init);
|
DValue* DtoInitializer(LLValue* target, Initializer* init);
|
||||||
|
|
||||||
// annotation generator
|
// annotation generator
|
||||||
|
@ -109,7 +109,7 @@ DValue* DtoBinRem(Type* resulttype, DValue* lhs, DValue* rhs);
|
||||||
void findDefaultTarget();
|
void findDefaultTarget();
|
||||||
|
|
||||||
/// get the default initializer of the type
|
/// get the default initializer of the type
|
||||||
LLConstant* DtoDefaultInit(Type* t);
|
LLConstant* DtoDefaultInit(Loc& loc, Type* t);
|
||||||
|
|
||||||
// fixup an overloaded intrinsic name string
|
// fixup an overloaded intrinsic name string
|
||||||
void DtoOverloadedIntrinsicName(TemplateInstance* ti, TemplateDeclaration* td, std::string& name);
|
void DtoOverloadedIntrinsicName(TemplateInstance* ti, TemplateDeclaration* td, std::string& name);
|
||||||
|
|
|
@ -42,7 +42,7 @@ LLConstant* DtoConstStructInitializer(StructInitializer* si)
|
||||||
assert(ini);
|
assert(ini);
|
||||||
VarDeclaration* vd = (VarDeclaration*)si->vars.data[i];
|
VarDeclaration* vd = (VarDeclaration*)si->vars.data[i];
|
||||||
assert(vd);
|
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));
|
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)
|
for (IrStruct::OffsetMap::iterator i=irstruct->offsets.begin(); i!=irstruct->offsets.end(); ++i)
|
||||||
{
|
{
|
||||||
IrStruct::Offset* so = &i->second;
|
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->init = finit;
|
||||||
so->var->ir.irField->constInit = finit;
|
so->var->ir.irField->constInit = finit;
|
||||||
}
|
}
|
||||||
|
|
|
@ -424,7 +424,7 @@ void TypeInfoTypedefDeclaration::llvmDefine()
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
LLConstant* ci = DtoConstInitializer(sd->basetype, sd->init);
|
LLConstant* ci = DtoConstInitializer(sd->loc, sd->basetype, sd->init);
|
||||||
std::string ciname(sd->mangle());
|
std::string ciname(sd->mangle());
|
||||||
ciname.append("__init");
|
ciname.append("__init");
|
||||||
llvm::GlobalVariable* civar = new llvm::GlobalVariable(DtoType(sd->basetype),true,llvm::GlobalValue::InternalLinkage,ci,ciname,gIR->module);
|
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