2 * sparse/check_param_mapper.c
4 * Copyright (C) 2009 Dan Carpenter.
6 * Licensed under the Open Software License version 1.1
11 * The idea behind this test is that if we have:
17 * Passing "bar" to foo() really means passing "bar" to baz();
19 * In this case it would print:
20 * info: param_mapper 0 => bar 1
30 static struct symbol
*func_sym
;
32 static void delete(struct sm_state
*sm
)
34 set_state(my_id
, sm
->name
, sm
->sym
, &undefined
);
37 static void match_function_def(struct symbol
*sym
)
42 FOR_EACH_PTR(func_sym
->ctype
.base_type
->arguments
, arg
) {
46 set_state(my_id
, arg
->ident
->name
, arg
, &argument
);
47 } END_FOR_EACH_PTR(arg
);
50 static int get_arg_num(struct expression
*expr
)
52 struct smatch_state
*state
;
54 struct symbol
*this_arg
;
57 expr
= strip_expr(expr
);
58 if (expr
->type
!= EXPR_SYMBOL
)
60 this_arg
= expr
->symbol
;
62 state
= get_state_expr(my_id
, expr
);
63 if (!state
|| state
!= &argument
)
67 FOR_EACH_PTR(func_sym
->ctype
.base_type
->arguments
, arg
) {
71 } END_FOR_EACH_PTR(arg
);
76 static void match_call(struct expression
*expr
)
78 struct expression
*tmp
;
83 if (expr
->fn
->type
!= EXPR_SYMBOL
)
86 func
= expr
->fn
->symbol_name
->name
;
89 FOR_EACH_PTR(expr
->args
, tmp
) {
90 tmp
= strip_expr(tmp
);
91 arg_num
= get_arg_num(tmp
);
93 sm_msg("info: param_mapper %d => %s %d", arg_num
, func
, i
);
95 } END_FOR_EACH_PTR(tmp
);
98 void check_param_mapper(int id
)
100 if (!option_param_mapper
)
103 add_modification_hook(my_id
, &delete);
104 add_hook(&match_function_def
, FUNC_DEF_HOOK
);
105 add_hook(&match_call
, FUNCTION_CALL_HOOK
);