Mesa (master): linker: Treat sized and unsized array types as the same

Ian Romanick idr at kemper.freedesktop.org
Mon Aug 30 05:17:10 UTC 2010


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

Author: Ian Romanick <ian.d.romanick at intel.com>
Date:   Sun Aug 29 22:07:49 2010 -0700

linker: Treat sized and unsized array types as the same

If two shaders contain variables declared with array types that have
the same base type but one is sized and the other is not, linking
should succeed.  I'm not super pleased with the way this is
implemented, and I am more convinced than ever that we need more
linker tests.  We especially need "negative" tests.

Fixes bugzilla #29697 and piglit test glsl-link-array-01.

---

 src/glsl/linker.cpp |   26 ++++++++++++++++++++------
 1 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/src/glsl/linker.cpp b/src/glsl/linker.cpp
index 3de069b..56e0bfd 100644
--- a/src/glsl/linker.cpp
+++ b/src/glsl/linker.cpp
@@ -343,12 +343,26 @@ cross_validate_globals(struct gl_shader_program *prog,
 	 ir_variable *const existing = variables.get_variable(var->name);
 	 if (existing != NULL) {
 	    if (var->type != existing->type) {
-	       linker_error_printf(prog, "%s `%s' declared as type "
-				   "`%s' and type `%s'\n",
-				   mode_string(var),
-				   var->name, var->type->name,
-				   existing->type->name);
-	       return false;
+	       /* Consider the types to be "the same" if both types are arrays
+		* of the same type and one of the arrays is implicitly sized.
+		* In addition, set the type of the linked variable to the
+		* explicitly sized array.
+		*/
+	       if (var->type->is_array()
+		   && existing->type->is_array()
+		   && (var->type->fields.array == existing->type->fields.array)
+		   && ((var->type->length == 0)
+		       || (existing->type->length == 0))) {
+		  if (existing->type->length == 0)
+		     existing->type = var->type;
+	       } else {
+		  linker_error_printf(prog, "%s `%s' declared as type "
+				      "`%s' and type `%s'\n",
+				      mode_string(var),
+				      var->name, var->type->name,
+				      existing->type->name);
+		  return false;
+	       }
 	    }
 
 	    /* FINISHME: Handle non-constant initializers.




More information about the mesa-commit mailing list