changeset 796:6e7a4c3b64d2

Error instead of assert when trying to build a default initializer for void[n].
author Christian Kamm <kamm incasoftware de>
date Sat, 29 Nov 2008 12:28:10 +0100
parents 06ba66bc0689
children 340acf1535d0
files gen/arrays.cpp gen/classes.cpp gen/llvmhelpers.cpp gen/llvmhelpers.h gen/structs.cpp gen/typinf.cpp
diffstat 6 files changed, 20 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/gen/arrays.cpp	Fri Nov 28 23:29:00 2008 +0100
+++ b/gen/arrays.cpp	Sat Nov 29 12:28:10 2008 +0100
@@ -289,7 +289,7 @@
         }
 
         if (!v)
-            v = DtoConstInitializer(t->nextOf(), init);
+            v = DtoConstInitializer(arrinit->loc, t->nextOf(), init);
         assert(v);
 
         inits[i] = v;
--- a/gen/classes.cpp	Fri Nov 28 23:29:00 2008 +0100
+++ b/gen/classes.cpp	Sat Nov 29 12:28:10 2008 +0100
@@ -491,7 +491,7 @@
     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;
     }
--- a/gen/llvmhelpers.cpp	Fri Nov 28 23:29:00 2008 +0100
+++ b/gen/llvmhelpers.cpp	Sat Nov 29 12:28:10 2008 +0100
@@ -971,11 +971,11 @@
 
     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 @@
 //      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* 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 @@
     return val;
 }
 
-LLConstant* DtoDefaultInit(Type* type)
+LLConstant* DtoDefaultInit(Loc& loc, Type* type)
 {
     Expression* exp = type->defaultInit();
     
@@ -1580,6 +1580,11 @@
     {
         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);
         }
--- a/gen/llvmhelpers.h	Fri Nov 28 23:29:00 2008 +0100
+++ b/gen/llvmhelpers.h	Sat Nov 29 12:28:10 2008 +0100
@@ -86,8 +86,8 @@
 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 @@
 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);
--- a/gen/structs.cpp	Fri Nov 28 23:29:00 2008 +0100
+++ b/gen/structs.cpp	Sat Nov 29 12:28:10 2008 +0100
@@ -42,7 +42,7 @@
         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 @@
     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;
     }
--- a/gen/typinf.cpp	Fri Nov 28 23:29:00 2008 +0100
+++ b/gen/typinf.cpp	Sat Nov 29 12:28:10 2008 +0100
@@ -424,7 +424,7 @@
     }
     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);