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:
12
module.cpp
12
module.cpp
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user