glsl: Explicitly NULL-check variables before making a dereference.
authorKenneth Graunke <kenneth@whitecape.org>
Tue, 13 Mar 2012 21:59:42 +0000 (14:59 -0700)
committerKenneth Graunke <kenneth@whitecape.org>
Mon, 26 Mar 2012 17:21:55 +0000 (10:21 -0700)
The constructor currently returns a ir_dereference_variable of error
type when provided NULL, but that's about to change in the next commit.

Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Eric Anholt <eric@anholt.net>
src/glsl/ast_to_hir.cpp

index 75d7e9d5793079b5c5917c87323a6e13edb0628c..ff56e33b7aaa2eb9f31b1384e1d0aca55e8136ed 100644 (file)
@@ -1692,14 +1692,14 @@ ast_expression::hir(exec_list *instructions,
       ir_variable *var = 
         state->symbols->get_variable(this->primary_expression.identifier);
 
-      result = new(ctx) ir_dereference_variable(var);
-
       if (var != NULL) {
         var->used = true;
+        result = new(ctx) ir_dereference_variable(var);
       } else {
         _mesa_glsl_error(& loc, state, "`%s' undeclared",
                          this->primary_expression.identifier);
 
+        result = ir_call::get_error_instruction(ctx);
         error_emitted = true;
       }
       break;