diff --git a/parse.yy b/parse.yy index 5bf48ec8..8241d357 100644 --- a/parse.yy +++ b/parse.yy @@ -909,11 +909,21 @@ struct_or_union_specifier } | struct_or_union '{' '}' { - Error(@1, "Empty struct definitions not allowed."); + llvm::SmallVector elementTypes; + llvm::SmallVector elementNames; + llvm::SmallVector elementPositions; + $$ = new StructType("", elementTypes, elementNames, elementPositions, + false, Variability::Unbound, @1); } | struct_or_union struct_or_union_name '{' '}' { - Error(@1, "Empty struct definitions not allowed."); + llvm::SmallVector elementTypes; + llvm::SmallVector elementNames; + llvm::SmallVector elementPositions; + StructType *st = new StructType($2, elementTypes, elementNames, elementPositions, + false, Variability::Unbound, @1); + m->symbolTable->AddType($2, st, @2); + $$ = st; } | struct_or_union struct_or_union_name { diff --git a/tests/empty-struct.ispc b/tests/empty-struct.ispc new file mode 100644 index 00000000..f8488e5c --- /dev/null +++ b/tests/empty-struct.ispc @@ -0,0 +1,13 @@ + +export uniform int width() { return programCount; } + +struct Foo { }; + +export void f_f(uniform float RET[], uniform float aFOO[]) { + uniform Foo f; + RET[programIndex] = sizeof(f); +} + +export void result(uniform float RET[]) { + RET[programIndex] = 1; +} diff --git a/type.cpp b/type.cpp index 47c2961e..ff772d78 100644 --- a/type.cpp +++ b/type.cpp @@ -1828,19 +1828,25 @@ StructType::StructType(const std::string &n, const llvm::SmallVector elementTypes; - for (int i = 0; i < GetElementCount(); ++i) { - const Type *type = GetElementType(i); - if (type == NULL) { - Assert(m->errorCount > 0); - return; + int nElements = GetElementCount(); + if (nElements == 0) { + elementTypes.push_back(LLVMTypes::Int8Type); + } + else { + for (int i = 0; i < nElements; ++i) { + const Type *type = GetElementType(i); + if (type == NULL) { + Assert(m->errorCount > 0); + return; + } + else if (CastType(type) != NULL) { + Error(elementPositions[i], "Method declarations are not " + "supported."); + return; + } + else + elementTypes.push_back(type->LLVMType(g->ctx)); } - else if (CastType(type) != NULL) { - Error(elementPositions[i], "Method declarations are not " - "supported."); - return; - } - else - elementTypes.push_back(type->LLVMType(g->ctx)); } if (lStructTypeMap.find(mname) == lStructTypeMap.end()) {