Improve error checking for unsized arrays.

Added support for resolving dimensions of multi-dimensional unsized arrays
from their initializer exprerssions (previously, only the first dimension
would be resolved.)

Added checks to make sure that no unsized array dimensions remain after
doing this (except for the first dimensision of array parameters to
functions.)
This commit is contained in:
Matt Pharr
2011-11-21 09:16:29 -08:00
parent 068ea3e4c4
commit d3e6879223
13 changed files with 140 additions and 29 deletions

View File

@@ -237,6 +237,18 @@ Module::AddGlobalVariable(Symbol *sym, Expr *initExpr, bool isConst) {
return;
}
sym->type = ArrayType::SizeUnsizedArrays(sym->type, initExpr);
if (sym->type == NULL)
return;
const ArrayType *at = dynamic_cast<const ArrayType *>(sym->type);
if (at != NULL && at->TotalElementCount() == 0) {
Error(sym->pos, "Illegal to declare a global variable with unsized "
"array dimensions that aren't set with an initializer "
"expression.");
return;
}
LLVM_TYPE_CONST llvm::Type *llvmType = sym->type->LLVMType(g->ctx);
// See if we have an initializer expression for the global. If so,