2 * Copyright (C) 2021 Oracle.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, see http://www.gnu.org/copyleft/gpl.txt
19 #include "smatch_slist.h"
20 #include "smatch_extra.h"
26 static bool is_post_minus(struct expression
*expr
)
28 expr
= strip_expr(expr
);
31 if (expr
->type
!= EXPR_POSTOP
)
33 if (expr
->op
!= SPECIAL_DECREMENT
)
38 static void match_post_loop(struct expression
*expr
)
40 struct statement
*stmt
;
42 expr
= strip_expr(expr
);
43 stmt
= expr_get_parent_stmt(expr
);
47 if (stmt
->type
!= STMT_ITERATOR
)
49 if (!is_post_minus(stmt
->iterator_post_condition
))
51 if (is_post_minus(stmt
->iterator_post_condition
))
52 set_state_expr(my_id
, stmt
->iterator_post_condition
->left
, &post_minus
);
55 static void match_condition(struct expression
*expr
)
57 if (get_state_expr(my_id
, expr
) != &post_minus
)
59 sm_warning("do while ends on '%s == -1'", expr_to_str(expr
));
62 void check_do_while_loop_limit(int id
)
65 add_hook(&match_post_loop
, CONDITION_HOOK
);
66 add_hook(&match_condition
, CONDITION_HOOK
);