[Mesa-dev] [PATCH 09/10] glsl: Track in each ir_variable whether it was ever assigned.

Eric Anholt eric at anholt.net
Mon Apr 16 16:59:53 PDT 2012


This will be used for some compile-and-link-time error checking, where
currently we've been doing error checking only at link time.
---
 src/glsl/ast_function.cpp |   29 ++++++++++++++++-------------
 src/glsl/ast_to_hir.cpp   |    4 ++++
 src/glsl/ir.h             |   13 +++++++++++++
 3 files changed, 33 insertions(+), 13 deletions(-)

diff --git a/src/glsl/ast_function.cpp b/src/glsl/ast_function.cpp
index 3940101..8bf0ba2 100644
--- a/src/glsl/ast_function.cpp
+++ b/src/glsl/ast_function.cpp
@@ -152,19 +152,22 @@ verify_parameter_modes(_mesa_glsl_parse_state *state,
 	    return false;
 	 }
 
-	 if (actual->variable_referenced()
-	     && actual->variable_referenced()->read_only) {
-	    _mesa_glsl_error(&loc, state,
-			     "function parameter '%s %s' references the "
-			     "read-only variable '%s'",
-			     mode, formal->name,
-			     actual->variable_referenced()->name);
-	    return false;
-	 } else if (!actual->is_lvalue()) {
-	    _mesa_glsl_error(&loc, state,
-			     "function parameter '%s %s' is not an lvalue",
-			     mode, formal->name);
-	    return false;
+	 ir_variable *var = actual->variable_referenced();
+	 if (var) {
+	    if (var->read_only) {
+	       _mesa_glsl_error(&loc, state,
+				"function parameter '%s %s' references the "
+				"read-only variable '%s'",
+				mode, formal->name,
+				actual->variable_referenced()->name);
+	       return false;
+	    } else if (!actual->is_lvalue()) {
+	       _mesa_glsl_error(&loc, state,
+				"function parameter '%s %s' is not an lvalue",
+				mode, formal->name);
+	       return false;
+	    }
+	    var->assigned = true;
 	 }
       }
 
diff --git a/src/glsl/ast_to_hir.cpp b/src/glsl/ast_to_hir.cpp
index 820c86c..80ea8bc 100644
--- a/src/glsl/ast_to_hir.cpp
+++ b/src/glsl/ast_to_hir.cpp
@@ -672,6 +672,10 @@ do_assignment(exec_list *instructions, struct _mesa_glsl_parse_state *state,
    void *ctx = state;
    bool error_emitted = (lhs->type->is_error() || rhs->type->is_error());
 
+   ir_variable *lhs_var = lhs->variable_referenced();
+   if (lhs_var)
+      lhs_var->assigned = true;
+
    if (!error_emitted) {
       if (non_lvalue_description != NULL) {
          _mesa_glsl_error(&lhs_loc, state,
diff --git a/src/glsl/ir.h b/src/glsl/ir.h
index d6c6a60..ddfaf36 100644
--- a/src/glsl/ir.h
+++ b/src/glsl/ir.h
@@ -353,10 +353,23 @@ public:
     * Several GLSL semantic checks require knowledge of whether or not a
     * variable has been used.  For example, it is an error to redeclare a
     * variable as invariant after it has been used.
+    *
+    * This is only maintained in the ast_to_hir.cpp path, not in
+    * Mesa's fixed function or ARB program paths.
     */
    unsigned used:1;
 
    /**
+    * Has this variable been statically assigned?
+    *
+    * This answers whether the variable was assigned in any path of
+    * the shader during ast_to_hir.  This doesn't answer whether it is
+    * still written after dead code removal, nor is it maintained in
+    * non-ast_to_hir.cpp (GLSL parsing) paths.
+    */
+   unsigned assigned:1;
+
+   /**
     * Storage class of the variable.
     *
     * \sa ir_variable_mode
-- 
1.7.10



More information about the mesa-dev mailing list