Mesa (master): glsl: Make ir_dereference_record constructor assert the variable exists.

Kenneth Graunke kwg at kemper.freedesktop.org
Mon Mar 26 10:24:29 PDT 2012


Module: Mesa
Branch: master
Commit: 2cd652f810e3417ff458f23a8c72a0c84e342258
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=2cd652f810e3417ff458f23a8c72a0c84e342258

Author: Kenneth Graunke <kenneth at whitecape.org>
Date:   Tue Mar 13 12:51:15 2012 -0700

glsl: Make ir_dereference_record constructor assert the variable exists.

Providing a NULL pointer to the ir_dereference_record() constructor
seems like a bad idea.  Currently, if provided NULL, it returns a
partially constructed value of error type.  However, none of the callers
are prepared to handle that scenario.

Code inspection shows that all callers do one of the following:
- Already NULL-check the argument prior to creating the dereference
- Already deference the argument (and thus would crash if it were NULL)
- Newly allocate the argument.

Thus, it should be safe to simply assert the value passed is not NULL.
This should also catch issues right away, rather than dying later.

Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
Reviewed-by: Eric Anholt <eric at anholt.net>

---

 src/glsl/ir.cpp |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/glsl/ir.cpp b/src/glsl/ir.cpp
index 3fc4a98..fb9a50e 100644
--- a/src/glsl/ir.cpp
+++ b/src/glsl/ir.cpp
@@ -1074,11 +1074,12 @@ ir_dereference_array::set_array(ir_rvalue *value)
 ir_dereference_record::ir_dereference_record(ir_rvalue *value,
 					     const char *field)
 {
+   assert(value != NULL);
+
    this->ir_type = ir_type_dereference_record;
    this->record = value;
    this->field = ralloc_strdup(this, field);
-   this->type = (this->record != NULL)
-      ? this->record->type->field_type(field) : glsl_type::error_type;
+   this->type = this->record->type->field_type(field);
 }
 
 
@@ -1090,8 +1091,7 @@ ir_dereference_record::ir_dereference_record(ir_variable *var,
    this->ir_type = ir_type_dereference_record;
    this->record = new(ctx) ir_dereference_variable(var);
    this->field = ralloc_strdup(this, field);
-   this->type = (this->record != NULL)
-      ? this->record->type->field_type(field) : glsl_type::error_type;
+   this->type = this->record->type->field_type(field);
 }
 
 bool



More information about the mesa-commit mailing list