+ switch_statement_t *const old_switch = current_switch;
+ current_switch = statement;
+
+ /* determine a free number for the default label */
+ unsigned long num_cases = 0;
+ long def_nr = 0;
+ for (case_label_statement_t *l = statement->first_case; l != NULL; l = l->next) {
+ if (l->expression == NULL) {
+ /* default case */
+ continue;
+ }
+ if (l->last_case >= l->first_case)
+ num_cases += l->last_case - l->first_case;
+ if (l->last_case > def_nr)
+ def_nr = l->last_case;
+ }
+
+ if (def_nr + 1 < 0) {
+ /* Bad: an overflow occurred, we cannot be sure that the
+ * maximum + 1 is a free number. Scan the values a second
+ * time to find a free number.
+ */
+ unsigned char *bits = xmalloc((num_cases + 7) >> 3);
+ unsigned long i;
+
+ memset(bits, 0, (num_cases + 7) >> 3);
+ for (case_label_statement_t *l = statement->first_case; l != NULL; l = l->next) {
+ if (l->expression == NULL) {
+ /* default case */
+ continue;
+ }
+ for (long cns = l->first_case; cns <= l->last_case; ++cns) {
+ if (cns >= 0 && (unsigned long)cns < num_cases)
+ bits[cns >> 3] |= (1 << (cns & 7));
+ }
+ }
+ /* We look at the first num_cases constants:
+ * Either they are densed, so we took the last (num_cases)
+ * one, or they are non densed, so we will find one free
+ * there...
+ */
+ for (i = 0; i < num_cases; ++i)
+ if ((bits[i >> 3] & (i & 7)) == 0)
+ break;
+
+ free(bits);
+ def_nr = i;
+ } else {
+ ++def_nr;
+ }
+ statement->default_proj_nr = def_nr;