From f9dc621ebe961f353ba4e85615e22ce95029b4dd Mon Sep 17 00:00:00 2001 From: Matt Pharr Date: Tue, 27 Mar 2012 09:17:40 -0700 Subject: [PATCH] Fix bug when doing pointer math with varying integer offsets. We were incorrectly trying to type convert the varying offset to a uniform value, which in turn led to an incorrect compile-time error. Fixes issue #201. --- expr.cpp | 1 + tests/ptr-math-variability.ispc | 12 ++++++++++++ 2 files changed, 13 insertions(+) create mode 100644 tests/ptr-math-variability.ispc diff --git a/expr.cpp b/expr.cpp index cacbb312..4f516382 100644 --- a/expr.cpp +++ b/expr.cpp @@ -2314,6 +2314,7 @@ BinaryExpr::TypeCheck() { if (type1->IsVaryingType()) { arg0 = TypeConvertExpr(arg0, type0->GetAsVaryingType(), "pointer addition"); + offsetType = offsetType->GetAsVaryingType(); Assert(arg0 != NULL); } diff --git a/tests/ptr-math-variability.ispc b/tests/ptr-math-variability.ispc new file mode 100644 index 00000000..4fa89206 --- /dev/null +++ b/tests/ptr-math-variability.ispc @@ -0,0 +1,12 @@ + +export uniform int width() { return programCount; } + + +export void f_f(uniform float RET[], uniform float aFOO[]) { + uniform float * uniform ptr = aFOO; + RET[programIndex] = *(ptr + programIndex) - 1; +} + +export void result(uniform float RET[]) { + RET[programIndex] = programIndex; +}