summaryrefslogtreecommitdiff
path: root/src/glsl/ast_to_hir.cpp
diff options
context:
space:
mode:
authorIan Romanick <ian.d.romanick@intel.com>2011-01-07 18:34:58 -0800
committerIan Romanick <ian.d.romanick@intel.com>2011-01-12 14:30:31 -0800
commitbd33055ef4b6dd18d6247ff7d9e47496ff4acc51 (patch)
tree3278235f89711604cd0f9349ab8ea9270bbd1baa /src/glsl/ast_to_hir.cpp
parentc3f000b3926988124a44ce7e8cd6588e46063058 (diff)
glsl: Track variable usage, use that to enforce semantics
In particular, variables cannot be redeclared invariant after being used. Fixes piglit test invariant-05.vert and bugzilla #29164. NOTE: This is a candidate for the 7.9 and 7.10 branches.
Diffstat (limited to 'src/glsl/ast_to_hir.cpp')
-rw-r--r--src/glsl/ast_to_hir.cpp18
1 files changed, 16 insertions, 2 deletions
diff --git a/src/glsl/ast_to_hir.cpp b/src/glsl/ast_to_hir.cpp
index c4bd7e64e2..a833be18f3 100644
--- a/src/glsl/ast_to_hir.cpp
+++ b/src/glsl/ast_to_hir.cpp
@@ -1623,6 +1623,7 @@ ast_expression::hir(exec_list *instructions,
result = new(ctx) ir_dereference_variable(var);
if (var != NULL) {
+ var->used = true;
type = result->type;
} else {
_mesa_glsl_error(& loc, state, "`%s' undeclared",
@@ -1797,8 +1798,16 @@ apply_type_qualifier_to_variable(const struct ast_type_qualifier *qual,
struct _mesa_glsl_parse_state *state,
YYLTYPE *loc)
{
- if (qual->flags.q.invariant)
- var->invariant = 1;
+ if (qual->flags.q.invariant) {
+ if (var->used) {
+ _mesa_glsl_error(loc, state,
+ "variable `%s' may not be redeclared "
+ "`invariant' after being used",
+ var->name);
+ } else {
+ var->invariant = 1;
+ }
+ }
/* FINISHME: Mark 'in' variables at global scope as read-only. */
if (qual->flags.q.constant || qual->flags.q.attribute
@@ -2005,6 +2014,11 @@ ast_declarator_list::hir(exec_list *instructions,
_mesa_glsl_error(& loc, state,
"`%s' cannot be marked invariant, fragment shader "
"inputs only\n", decl->identifier);
+ } else if (earlier->used) {
+ _mesa_glsl_error(& loc, state,
+ "variable `%s' may not be redeclared "
+ "`invariant' after being used",
+ earlier->name);
} else {
earlier->invariant = true;
}