From 158bd6ef9e1c12f44aca5b3417382fbc4e0ae3e7 Mon Sep 17 00:00:00 2001 From: Matt Pharr Date: Thu, 28 Jul 2011 11:38:56 +0100 Subject: [PATCH] Fix bug with initializer expression lists for globlal/static array-typed variables. --- module.cpp | 8 ++++++-- tests/static-array-init-1.ispc | 13 +++++++++++++ tests/static-array-init.ispc | 13 +++++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 tests/static-array-init-1.ispc create mode 100644 tests/static-array-init.ispc diff --git a/module.cpp b/module.cpp index 18f0438d..2250d032 100644 --- a/module.cpp +++ b/module.cpp @@ -516,8 +516,12 @@ Module::AddGlobal(DeclSpecs *ds, Declarator *decl) { decl->initExpr = decl->initExpr->TypeCheck(); if (decl->initExpr != NULL) { // We need to make sure the initializer expression is - // the same type as the global - decl->initExpr = decl->initExpr->TypeConv(decl->sym->type, "initializer"); + // the same type as the global. (But not if it's an + // ExprList; they don't have types per se / can't type + // convert themselves anyway.) + if (dynamic_cast(decl->initExpr) == NULL) + decl->initExpr = + decl->initExpr->TypeConv(decl->sym->type, "initializer"); if (decl->initExpr != NULL) { decl->initExpr = decl->initExpr->Optimize(); diff --git a/tests/static-array-init-1.ispc b/tests/static-array-init-1.ispc new file mode 100644 index 00000000..2020f8a8 --- /dev/null +++ b/tests/static-array-init-1.ispc @@ -0,0 +1,13 @@ + +static uniform float foo[4] = { 1, 2, 3, 4 }; + +export uniform int width() { return programCount; } + + +export void f_fu(uniform float RET[], uniform float aFOO[], uniform float b) { + RET[programIndex] = foo[b-3]; +} + +export void result(uniform float RET[]) { + RET[programIndex] = 3; +} diff --git a/tests/static-array-init.ispc b/tests/static-array-init.ispc new file mode 100644 index 00000000..bc12bfc8 --- /dev/null +++ b/tests/static-array-init.ispc @@ -0,0 +1,13 @@ + +static uniform int foo[4] = { 1, 2, 3, 4 }; + +export uniform int width() { return programCount; } + + +export void f_fu(uniform float RET[], uniform float aFOO[], uniform float b) { + RET[programIndex] = foo[b-3]; +} + +export void result(uniform float RET[]) { + RET[programIndex] = 3; +}