2 * Copyright (C) 2016 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_extra.h"
20 #include "smatch_slist.h"
26 static void handle_test_functions(struct expression
*expr
)
28 struct expression
*tmp
;
29 struct statement
*stmt
;
32 while (expr
&& expr
->type
== EXPR_ASSIGNMENT
&& expr
->op
== '=')
33 expr
= strip_expr(expr
->right
);
36 expr
->type
!= EXPR_CALL
||
37 expr
->fn
->type
!= EXPR_SYMBOL
||
38 !expr
->fn
->symbol_name
)
40 if (!strstr(expr
->fn
->symbol_name
->name
, "test"))
43 while ((tmp
= expr_get_parent_expr(expr
))) {
50 * FIXME: This doesn't work for assignments like:
52 * free = dec_and_test(foo);
56 * Maybe we should just say everything is on an atomic_dec path at this
57 * point. That probably works fine. The other solution would be to
58 * store the variable and look up the state of it or something...
62 stmt
= expr_get_parent_stmt(expr
);
63 if (!stmt
|| stmt
->type
!= STMT_IF
) {
64 /* See above comment. I decided to go with the easy option */
65 set_state(my_id
, "dec_path", NULL
, &zero_path
);
69 set_true_false_states(my_id
, "dec_path", NULL
, &zero_path
, NULL
);
72 static void match_dec(struct expression
*expr
, const char *name
, struct symbol
*sym
)
74 handle_test_functions(expr
);
77 int on_atomic_dec_path(void)
79 return get_state(my_id
, "dec_path", NULL
) == &zero_path
;
82 void register_kernel_atomic_dec_test_path(int id
)
86 if (option_project
!= PROJ_KERNEL
)
89 add_refcount_dec_hook(&match_dec
);