[Mesa-dev] [PATCH 1/2] intel: fail to compile in case of bad uniform access

Frank Henigman fjhenigman at google.com
Mon Jan 28 17:06:58 PST 2013


An assertion in fs_visitor::remove_dead_constants() would fail on
code like this, which accesses a non-existent uniform:
  uniform vec u[1];
  ...
  a += u[0] + u[1];
Shader code is checked for that error, but apparently only before
transformations like loop unrolling.  So the following code would get
transformed to the same as above and then the assertion would fail:
  for (int i = 0; i < 2; ++i) a += u[i];

This patch changes the assertion failure to a compile failure.

https://bugs.freedesktop.org/show_bug.cgi?id=59429

Signed-off-by: Frank Henigman <fjhenigman at google.com>
---
 src/mesa/drivers/dri/i965/brw_fs.cpp | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/mesa/drivers/dri/i965/brw_fs.cpp b/src/mesa/drivers/dri/i965/brw_fs.cpp
index 8e57eb0..548f7d6 100644
--- a/src/mesa/drivers/dri/i965/brw_fs.cpp
+++ b/src/mesa/drivers/dri/i965/brw_fs.cpp
@@ -1467,7 +1467,12 @@ fs_visitor::remove_dead_constants()
 	    if (inst->src[i].file != UNIFORM)
 	       continue;
 
-	    assert(constant_nr < (int)c->prog_data.nr_params);
+	    if (constant_nr >= (int)c->prog_data.nr_params) {
+	       ralloc_free(this->params_remap);
+	       this->params_remap = NULL;
+	       fail("accessed non-existent uniform");
+	       return false;
+	    }
 
 	    /* For now, set this to non-negative.  We'll give it the
 	     * actual new number in a moment, in order to keep the
-- 
1.8.1



More information about the mesa-dev mailing list