Print this page
10703 smatch unreachable code checking needs reworking
Reviewed by: Toomas Soome <tsoome@me.com>
Reviewed by: Yuri Pankov <yuri.pankov@nexenta.com>


 155         case STMT_COMPOUND: /* after a switch before a case stmt */
 156         case STMT_RANGE:
 157         case STMT_CASE:
 158                 return;
 159         case STMT_DECLARATION: /* switch (x) { int a; case foo: ... */
 160                 print_unreached_initializers(stmt->declaration);
 161                 return;
 162         case STMT_RETURN: /* gcc complains if you don't have a return statement */
 163                 if (is_last_stmt(stmt))
 164                         return;
 165                 break;
 166         case STMT_GOTO:
 167                 /* people put extra breaks inside switch statements */
 168                 if (stmt->goto_label && stmt->goto_label->type == SYM_NODE &&
 169                     strcmp(stmt->goto_label->ident->name, "break") == 0)
 170                         return;
 171                 break;
 172         default:
 173                 break;
 174         }
 175         sm_msg("info: ignoring unreachable code.");
 176         print_unreached = 0;
 177 }
 178 
 179 static int is_turn_off(char *name)
 180 {
 181         char *tmp;
 182 
 183         if (!name)
 184                 return 0;
 185 
 186         FOR_EACH_PTR(turn_off_names, tmp) {
 187                 if (strcmp(tmp, name) == 0)
 188                         return 1;
 189         } END_FOR_EACH_PTR(tmp);
 190 
 191         return 0;
 192 }
 193 
 194 static char *get_function_name(struct statement *stmt)
 195 {




 155         case STMT_COMPOUND: /* after a switch before a case stmt */
 156         case STMT_RANGE:
 157         case STMT_CASE:
 158                 return;
 159         case STMT_DECLARATION: /* switch (x) { int a; case foo: ... */
 160                 print_unreached_initializers(stmt->declaration);
 161                 return;
 162         case STMT_RETURN: /* gcc complains if you don't have a return statement */
 163                 if (is_last_stmt(stmt))
 164                         return;
 165                 break;
 166         case STMT_GOTO:
 167                 /* people put extra breaks inside switch statements */
 168                 if (stmt->goto_label && stmt->goto_label->type == SYM_NODE &&
 169                     strcmp(stmt->goto_label->ident->name, "break") == 0)
 170                         return;
 171                 break;
 172         default:
 173                 break;
 174         }
 175         sm_warning("ignoring unreachable code.");
 176         print_unreached = 0;
 177 }
 178 
 179 static int is_turn_off(char *name)
 180 {
 181         char *tmp;
 182 
 183         if (!name)
 184                 return 0;
 185 
 186         FOR_EACH_PTR(turn_off_names, tmp) {
 187                 if (strcmp(tmp, name) == 0)
 188                         return 1;
 189         } END_FOR_EACH_PTR(tmp);
 190 
 191         return 0;
 192 }
 193 
 194 static char *get_function_name(struct statement *stmt)
 195 {