Mesa (master): glsl: Generate an error for array-of-array declarations

Ian Romanick idr at kemper.freedesktop.org
Fri Oct 28 13:29:31 PDT 2011


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

Author: Ian Romanick <ian.d.romanick at intel.com>
Date:   Mon Oct 24 11:45:50 2011 -0700

glsl: Generate an error for array-of-array declarations

Other parts of the code already caught things like 'float x[4][2]'.
However, nothing caught 'float [4] x[2]'.

Fixes piglit test array-multidimensional-new-syntax.vert.

NOTE: This is candidate for the 7.11 branch.

Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>

---

 src/glsl/ast_to_hir.cpp |   16 ++++++++++++++--
 1 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/src/glsl/ast_to_hir.cpp b/src/glsl/ast_to_hir.cpp
index fa6206e..a60711d 100644
--- a/src/glsl/ast_to_hir.cpp
+++ b/src/glsl/ast_to_hir.cpp
@@ -1812,7 +1812,17 @@ process_array_type(YYLTYPE *loc, const glsl_type *base, ast_node *array_size,
 {
    unsigned length = 0;
 
-   /* FINISHME: Reject delcarations of multidimensional arrays. */
+   /* From page 19 (page 25) of the GLSL 1.20 spec:
+    *
+    *     "Only one-dimensional arrays may be declared."
+    */
+   if (base->is_array()) {
+      _mesa_glsl_error(loc, state,
+		       "invalid array of `%s' (only one-dimensional arrays "
+		       "may be declared)",
+		       base->name);
+      return glsl_type::error_type;
+   }
 
    if (array_size != NULL) {
       exec_list dummy_instructions;
@@ -2480,6 +2490,8 @@ ast_declarator_list::hir(exec_list *instructions,
       if (decl->is_array) {
 	 var_type = process_array_type(&loc, decl_type, decl->array_size,
 				       state);
+	 if (var_type->is_error())
+	    continue;
       } else {
 	 var_type = decl_type;
       }
@@ -2921,7 +2933,7 @@ ast_parameter_declarator::hir(exec_list *instructions,
       type = process_array_type(&loc, type, this->array_size, state);
    }
 
-   if (type->array_size() == 0) {
+   if (!type->is_error() && type->array_size() == 0) {
       _mesa_glsl_error(&loc, state, "arrays passed as parameters must have "
 		       "a declared size.");
       type = glsl_type::error_type;



More information about the mesa-commit mailing list