Mesa (master): glsl: Catch redeclaration of interface block instance names at compile time.

Paul Berry stereotype441 at kemper.freedesktop.org
Thu Oct 10 21:46:58 UTC 2013


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

Author: Paul Berry <stereotype441 at gmail.com>
Date:   Sat Sep 28 07:45:00 2013 -0700

glsl: Catch redeclaration of interface block instance names at compile time.

>From section 4.1.9 (Arrays) of the GLSL 4.40 spec (as of revision 7):

    However, unless noted otherwise, blocks cannot be redeclared;
    an unsized array in a user-declared block cannot be sized
    through redeclaration.

The only place where the spec notes that interface blocks can be
redeclared is to allow for redeclaration of built-in interface blocks
such as gl_PerVertex.  Therefore, user-defined interface blocks can
never be redeclared.  This is a clarification of previous intent (see
Khronos bug 10659).

We were already preventing interface block redeclaration using the
same block name at compile time, but we weren't preventing interface
block redeclaration using the same instance name (and different block
names) at compile time.  And we weren't preventing an instance name
from conflicting with a previously-declared ordinary variable.

In practice the problem would be caught at link time, but only because
of a coincidence: since ast_interface_block::hir() wasn't doing any
checking to see if the instance name already existed in the shader, it
was creating a second ir_variable in the shader having the same name
but a different type.  Coincidentally, when the linker checked for
intrastage consistency of global variable declarations, it treated the
two declarations from the same shader as a conflict, so it reported a
link error.

But it seems dangerous to rely on that linker behaviour to catch
illegal redeclarations that really ought to be detected at compile
time.

Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>

---

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

diff --git a/src/glsl/ast_to_hir.cpp b/src/glsl/ast_to_hir.cpp
index 2e73c4f..3c788de 100644
--- a/src/glsl/ast_to_hir.cpp
+++ b/src/glsl/ast_to_hir.cpp
@@ -4813,8 +4813,14 @@ ast_interface_block::hir(exec_list *instructions,
       var->init_interface_type(block_type);
       if (state->target == geometry_shader && var_mode == ir_var_shader_in)
          handle_geometry_shader_input_decl(state, loc, var);
-      state->symbols->add_variable(var);
-      instructions->push_tail(var);
+
+      if (state->symbols->get_variable(this->instance_name)) {
+         _mesa_glsl_error(&loc, state, "`%s' redeclared", this->instance_name);
+         delete var;
+      } else {
+         state->symbols->add_variable(var);
+         instructions->push_tail(var);
+      }
    } else {
       /* In order to have an array size, the block must also be declared with
        * an instane name.




More information about the mesa-commit mailing list