Mesa (master): glsl: Throw the required error when a case label is a non-constant.

Eric Anholt anholt at kemper.freedesktop.org
Fri Feb 3 10:29:55 UTC 2012


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

Author: Eric Anholt <eric at anholt.net>
Date:   Sat Jan 28 11:43:22 2012 -0800

glsl: Throw the required error when a case label is a non-constant.

It's not quite spelled out in the spec text, but the grammar indicates
that only constant values are allowed as switch() case labels (and
only constant values make sense, anyway).

Fixes piglit glsl-1.30/compiler/switch-statement/switch-case-uniform-int.vert.

NOTE: This is a candidate for the 8.0 branch.

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

---

 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 25ccdab..28aff39 100644
--- a/src/glsl/ast_to_hir.cpp
+++ b/src/glsl/ast_to_hir.cpp
@@ -3697,14 +3697,26 @@ ast_switch_statement::hir(exec_list *instructions,
 	/* Conditionally set fallthru state based on
 	 * comparison of cached test expression value to case label.
 	 */
-	ir_rvalue *const test_val = this->test_value->hir(instructions, state);
+	ir_rvalue *const label_rval = this->test_value->hir(instructions, state);
+	ir_constant *label_const = label_rval->constant_expression_value();
+
+	if (!label_const) {
+	   YYLTYPE loc = this->test_value->get_location();
+
+	   _mesa_glsl_error(& loc, state,
+			    "switch statement case label must be a "
+			    "constant expression");
+
+	   /* Stuff a dummy value in to allow processing to continue. */
+	   label_const = new(ctx) ir_constant(0);
+	}
 
 	ir_dereference_variable *deref_test_var =
 	   new(ctx) ir_dereference_variable(state->switch_state.test_var);
 
 	ir_rvalue *const test_cond = new(ctx) ir_expression(ir_binop_all_equal,
 							    glsl_type::bool_type,
-							    test_val,
+							    label_const,
 							    deref_test_var);
 
 	ir_assignment *set_fallthru_on_test =




More information about the mesa-commit mailing list