Mesa (7.9): glsl: Inherrit type of declared variable from initializer after processing assignment

Ian Romanick idr at kemper.freedesktop.org
Fri Dec 17 22:54:20 UTC 2010


Module: Mesa
Branch: 7.9
Commit: 7b6b66d617b1f14f79fb7af2dad268a68e35b9e3
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=7b6b66d617b1f14f79fb7af2dad268a68e35b9e3

Author: Ian Romanick <ian.d.romanick at intel.com>
Date:   Fri Dec 17 13:50:40 2010 -0800

glsl: Inherrit type of declared variable from initializer after processing assignment

do_assignment may apply implicit conversions to coerce the base type
of initializer to the base type of the variable being declared.  Fixes
piglit test glsl-implicit-conversion-02 (bugzilla #32287).  This
probably also fixes bugzilla #32273.

NOTE: This is a candidate for the 7.9 branch and the 7.10 branch.
(cherry picked from commit d7f27e2e76eac9bc2ee0fa36f52542fdcb9563dd)

Conflicts:

	src/glsl/ast_to_hir.cpp

---

 src/glsl/ast_to_hir.cpp |   25 +++++++++++++++++--------
 1 files changed, 17 insertions(+), 8 deletions(-)

diff --git a/src/glsl/ast_to_hir.cpp b/src/glsl/ast_to_hir.cpp
index 74d6308..53d8e4b 100644
--- a/src/glsl/ast_to_hir.cpp
+++ b/src/glsl/ast_to_hir.cpp
@@ -2039,6 +2039,17 @@ ast_declarator_list::hir(exec_list *instructions,
 	    if (this->type->qualifier.constant)
 	       var->read_only = false;
 
+	    /* Never emit code to initialize a uniform.
+	     */
+	    const glsl_type *initializer_type;
+	    if (!this->type->qualifier.uniform) {
+	       result = do_assignment(&initializer_instructions, state,
+				      lhs, rhs,
+				      this->get_location());
+	       initializer_type = result->type;
+	    } else
+	       initializer_type = rhs->type;
+
 	    /* If the declared variable is an unsized array, it must inherrit
 	     * its full type from the initializer.  A declaration such as
 	     *
@@ -2053,16 +2064,14 @@ ast_declarator_list::hir(exec_list *instructions,
 	     *
 	     * If the declared variable is not an array, the types must
 	     * already match exactly.  As a result, the type assignment
-	     * here can be done unconditionally.
+	     * here can be done unconditionally.  For non-uniforms the call
+	     * to do_assignment can change the type of the initializer (via
+	     * the implicit conversion rules).  For uniforms the initializer
+	     * must be a constant expression, and the type of that expression
+	     * was validated above.
 	     */
-	    var->type = rhs->type;
+	    var->type = initializer_type;
 
-	    /* Never emit code to initialize a uniform.
-	     */
-	    if (!this->type->qualifier.uniform)
-	       result = do_assignment(&initializer_instructions, state,
-				      lhs, rhs,
-				      this->get_location());
 	    var->read_only = temp;
 	 }
       }




More information about the mesa-commit mailing list