Mesa (master): glsl: Add error case for switch() with two default cases.
Eric Anholt
anholt at kemper.freedesktop.org
Fri Feb 3 10:29:55 UTC 2012
Module: Mesa
Branch: master
Commit: 57e44371a5b6aa8122b6a482ed6bd33e797ea1d2
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=57e44371a5b6aa8122b6a482ed6bd33e797ea1d2
Author: Eric Anholt <eric at anholt.net>
Date: Mon Jan 30 09:50:35 2012 -0800
glsl: Add error case for switch() with two default cases.
Fixes piglit switch-case-duplicated.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 | 15 +++++++++++++++
src/glsl/glsl_parser_extras.h | 1 +
2 files changed, 16 insertions(+), 0 deletions(-)
diff --git a/src/glsl/ast_to_hir.cpp b/src/glsl/ast_to_hir.cpp
index 4f328ad..c580359 100644
--- a/src/glsl/ast_to_hir.cpp
+++ b/src/glsl/ast_to_hir.cpp
@@ -3537,6 +3537,7 @@ ast_switch_statement::hir(exec_list *instructions,
state->switch_state.switch_nesting_ast = this;
state->switch_state.labels_ht = hash_table_ctor(0, hash_table_pointer_hash,
hash_table_pointer_compare);
+ state->switch_state.previous_default = NULL;
/* Initalize is_fallthru state to false.
*/
@@ -3749,6 +3750,20 @@ ast_switch_statement::hir(exec_list *instructions,
instructions->push_tail(set_fallthru_on_test);
} else { /* default case */
+ if (state->switch_state.previous_default) {
+ printf("a\n");
+ YYLTYPE loc = this->get_location();
+ _mesa_glsl_error(& loc, state,
+ "multiple default labels in one switch");
+
+ printf("b\n");
+
+ loc = state->switch_state.previous_default->get_location();
+ _mesa_glsl_error(& loc, state,
+ "this is the first default label");
+ }
+ state->switch_state.previous_default = this;
+
/* Set falltrhu state.
*/
ir_assignment *set_fallthru =
diff --git a/src/glsl/glsl_parser_extras.h b/src/glsl/glsl_parser_extras.h
index d5d5101..ee8f71b 100644
--- a/src/glsl/glsl_parser_extras.h
+++ b/src/glsl/glsl_parser_extras.h
@@ -51,6 +51,7 @@ struct glsl_switch_state {
/** Table of constant values already used in case labels */
struct hash_table *labels_ht;
+ class ast_case_label *previous_default;
bool is_switch_innermost; // if switch stmt is closest to break, ...
};
More information about the mesa-commit
mailing list