glsl: Add error case for switch() with two default cases.
authorEric Anholt <eric@anholt.net>
Mon, 30 Jan 2012 17:50:35 +0000 (09:50 -0800)
committerEric Anholt <eric@anholt.net>
Fri, 3 Feb 2012 10:07:04 +0000 (11:07 +0100)
Fixes piglit switch-case-duplicated.vert.

NOTE: This is a candidate for the 8.0 branch.

Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
src/glsl/ast_to_hir.cpp
src/glsl/glsl_parser_extras.h

index 4f328ad8f46df519e5ea5f992d3c27827fb300ec..c580359fdd0a41f74ba031a4df04ef0fa5c25ce0 100644 (file)
@@ -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 =
index d5d5101a8208c1975e59757a093501fa3d01428b..ee8f71b82800c575298cfe9d19a8c6213ee99304 100644 (file)
@@ -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, ...
 };