[Mesa-dev] [PATCH 5/5] glsl: Make ir_dereference_variable ctor assert the variable exists.

Kenneth Graunke kenneth at whitecape.org
Tue Mar 20 12:22:36 PDT 2012


This also seems like a bad idea.  There were too many instances for me
to thoroughly scan the code as I did with the last two patches, but a
quick scan indicated that most callers newly allocate a variable,
dereference it, or NULL-check.  In some cases, it wasn't clear that the
value would be non-NULL, but they didn't check for error_type either.

At any rate, not checking for this is a bug, and assertions will trigger
it earlier and more reliably than returning error_type.

Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
---
 src/glsl/ir.cpp |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/src/glsl/ir.cpp b/src/glsl/ir.cpp
index fb9a50e..3c9d6e1 100644
--- a/src/glsl/ir.cpp
+++ b/src/glsl/ir.cpp
@@ -1026,9 +1026,11 @@ ir_loop::ir_loop()
 
 ir_dereference_variable::ir_dereference_variable(ir_variable *var)
 {
+   assert(var != NULL);
+
    this->ir_type = ir_type_dereference_variable;
    this->var = var;
-   this->type = (var != NULL) ? var->type : glsl_type::error_type;
+   this->type = var->type;
 }
 
 
-- 
1.7.7.6



More information about the mesa-dev mailing list