From 977b983771ef8caad2e1067075df3c84c5e116ea Mon Sep 17 00:00:00 2001 From: Matt Pharr Date: Mon, 6 Feb 2012 07:44:45 -0800 Subject: [PATCH] Issue error on "void" typed variable, function parameter, or struct member. --- decl.cpp | 17 ++++++++++++++++- module.cpp | 5 +++++ tests_errors/void-1.ispc | 5 +++++ tests_errors/void-2.ispc | 5 +++++ tests_errors/void-3.ispc | 5 +++++ tests_errors/void-4.ispc | 3 +++ tests_errors/void-array-1.ispc | 5 +++++ tests_errors/void-array-2.ispc | 4 ++++ tests_errors/void-array-3.ispc | 7 +++++++ type.cpp | 1 + 10 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 tests_errors/void-1.ispc create mode 100644 tests_errors/void-2.ispc create mode 100644 tests_errors/void-3.ispc create mode 100644 tests_errors/void-4.ispc create mode 100644 tests_errors/void-array-1.ispc create mode 100644 tests_errors/void-array-2.ispc create mode 100644 tests_errors/void-array-3.ispc diff --git a/decl.cpp b/decl.cpp index c62f0b6f..5661c4a3 100644 --- a/decl.cpp +++ b/decl.cpp @@ -332,6 +332,11 @@ Declarator::GetType(const Type *base, DeclSpecs *ds) const { break; case DK_ARRAY: + if (type == AtomicType::Void) { + Error(pos, "Arrays of \"void\" type are illegal."); + return NULL; + } + type = new ArrayType(type, arraySize); if (child) return child->GetType(type, ds); @@ -358,6 +363,11 @@ Declarator::GetType(const Type *base, DeclSpecs *ds) const { "function parameter declaration for parameter \"%s\".", lGetStorageClassName(d->declSpecs->storageClass), sym->name.c_str()); + if (sym->type == AtomicType::Void) { + Error(sym->pos, "Parameter with type \"void\" illegal in function " + "parameter list."); + sym->type = NULL; + } const ArrayType *at = dynamic_cast(sym->type); if (at != NULL) { @@ -544,7 +554,9 @@ Declaration::GetVariableDeclarations() const { Symbol *sym = decl->GetSymbol(); sym->type = sym->type->ResolveUnboundVariability(Type::Varying); - if (dynamic_cast(sym->type) == NULL) { + if (sym->type == AtomicType::Void) + Error(sym->pos, "\"void\" type variable illegal in declaration."); + else if (dynamic_cast(sym->type) == NULL) { m->symbolTable->AddVariable(sym); vars.push_back(VariableDeclaration(sym, decl->initExpr)); } @@ -611,6 +623,9 @@ GetStructTypesNamesPositions(const std::vector &sd, Symbol *sym = d->GetSymbol(); + if (sym->type == AtomicType::Void) + Error(d->pos, "\"void\" type illegal for struct member."); + const ArrayType *arrayType = dynamic_cast(sym->type); if (arrayType != NULL && arrayType->GetElementCount() == 0) { diff --git a/module.cpp b/module.cpp index df09955a..3881ae2b 100644 --- a/module.cpp +++ b/module.cpp @@ -237,6 +237,11 @@ Module::AddGlobalVariable(Symbol *sym, Expr *initExpr, bool isConst) { return; } + if (sym->type == AtomicType::Void) { + Error(sym->pos, "\"void\" type global variable is illegal."); + return; + } + sym->type = ArrayType::SizeUnsizedArrays(sym->type, initExpr); if (sym->type == NULL) return; diff --git a/tests_errors/void-1.ispc b/tests_errors/void-1.ispc new file mode 100644 index 00000000..44f19555 --- /dev/null +++ b/tests_errors/void-1.ispc @@ -0,0 +1,5 @@ +// "void" type variable illegal in declaration + +int func() { + void x; +} diff --git a/tests_errors/void-2.ispc b/tests_errors/void-2.ispc new file mode 100644 index 00000000..3cd50dcf --- /dev/null +++ b/tests_errors/void-2.ispc @@ -0,0 +1,5 @@ +// Parameter with type "void" illegal in function parameter list + +void func(void x, void y) { + return x+y; +} diff --git a/tests_errors/void-3.ispc b/tests_errors/void-3.ispc new file mode 100644 index 00000000..7910de54 --- /dev/null +++ b/tests_errors/void-3.ispc @@ -0,0 +1,5 @@ +// "void" type illegal for struct member + +struct Foo { + void x; +}; diff --git a/tests_errors/void-4.ispc b/tests_errors/void-4.ispc new file mode 100644 index 00000000..d2f8f48f --- /dev/null +++ b/tests_errors/void-4.ispc @@ -0,0 +1,3 @@ +// "void" type global variable is illegal + +void x; diff --git a/tests_errors/void-array-1.ispc b/tests_errors/void-array-1.ispc new file mode 100644 index 00000000..1e9aaa5c --- /dev/null +++ b/tests_errors/void-array-1.ispc @@ -0,0 +1,5 @@ +// Arrays of "void" type are illegal + +float f_fu(uniform void aFOO[]) { + return 0; +} diff --git a/tests_errors/void-array-2.ispc b/tests_errors/void-array-2.ispc new file mode 100644 index 00000000..79d646e6 --- /dev/null +++ b/tests_errors/void-array-2.ispc @@ -0,0 +1,4 @@ +// Arrays of "void" type are illegal + +uniform void aFOO[] = { NULL }; + diff --git a/tests_errors/void-array-3.ispc b/tests_errors/void-array-3.ispc new file mode 100644 index 00000000..2cca0f37 --- /dev/null +++ b/tests_errors/void-array-3.ispc @@ -0,0 +1,7 @@ +// Arrays of "void" type are illegal + +struct Foo { + void aFOO[]; +}; + + diff --git a/type.cpp b/type.cpp index db68b47a..f771dc73 100644 --- a/type.cpp +++ b/type.cpp @@ -1165,6 +1165,7 @@ ArrayType::ArrayType(const Type *c, int a) : child(c), numElements(a) { // 0 -> unsized array. Assert(numElements >= 0); + Assert(c != AtomicType::Void); }