[Mesa-dev] [PATCH 3/4] glsl: Fix illegal implicit type conversions

Chad Versace chad at chad-versace.us
Tue Jul 26 23:36:01 PDT 2011


glsl_type::implicit_conversion_compare() allowed the following illegal
implicit conversions:
        bool -> float
        bvecN -> vecN

        int   -> uint
        ivecN -> uvecN
        uint  -> int
        uvecN -> ivecN

Fixes Piglit
spec/glsl-1.20/compiler/built-in-functions/outerProduct-bvec*.vert.

If cherry-picked, the following commit is required:
    glsl: Refactor ast_function.cpp:type_compare() into a glsl_type method

Note: This is a candidate for the 7.10 and 7.11 branches.
CC: Ian Romanick <ian.d.romanick at intel.com>
Signed-off-by: Chad Versace <chad at chad-versace.us>
---
 src/glsl/glsl_types.cpp |   20 +++++++++++---------
 1 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/src/glsl/glsl_types.cpp b/src/glsl/glsl_types.cpp
index 752c1af..dd62502 100644
--- a/src/glsl/glsl_types.cpp
+++ b/src/glsl/glsl_types.cpp
@@ -466,20 +466,22 @@ int glsl_type::implicit_conversion_compare(const glsl_type *desired) const {
    case GLSL_TYPE_UINT:
    case GLSL_TYPE_INT:
    case GLSL_TYPE_BOOL:
-      /* There is no implicit conversion to or from integer types or bool. */
-      if ((this->is_integer() != desired->is_integer())
-	  || (this->is_boolean() != desired->is_boolean()))
+      /* There is no implicit conversion among any of the above types. */
+      if (this->base_type == desired->base_type
+	    && this->vector_elements == desired->vector_elements
+	    && this->matrix_columns == desired->matrix_columns)
+	 return 1;
+      else
 	 return -1;
 
-      /* FALLTHROUGH */
-
    case GLSL_TYPE_FLOAT:
-      if ((this->vector_elements != desired->vector_elements)
-	  || (this->matrix_columns != desired->matrix_columns))
+      if ((this->is_float() || this->is_integer())
+	    && this->vector_elements == desired->vector_elements
+	    && this->matrix_columns == desired->matrix_columns)
+	 return 1;
+      else
 	 return -1;
 
-      return 1;
-
    case GLSL_TYPE_SAMPLER:
    case GLSL_TYPE_STRUCT:
       /* Samplers and structures must match exactly. */
-- 
1.7.6



More information about the mesa-dev mailing list