1 /* 2 * Copyright (C) 2009 Dan Carpenter. 3 * 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. 8 * 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. 13 * 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 16 */ 17 18 /* 19 * The idea behind this test is that if we have: 20 * void foo(int bar) 21 * { 22 * baz(1, bar); 23 * } 24 * 25 * Passing "bar" to foo() really means passing "bar" to baz(); 26 * 27 * In this case it would print: 28 * info: param_mapper 0 => bar 1 29 * 30 */ 31 32 #include "smatch.h" 33 34 static int my_id; 35 match_call(struct expression * expr)36static void match_call(struct expression *expr) 37 { 38 struct expression *tmp; 39 char *func; 40 int arg_num; 41 int i; 42 43 if (expr->fn->type != EXPR_SYMBOL) 44 return; 45 46 func = expr->fn->symbol_name->name; 47 48 i = -1; 49 FOR_EACH_PTR(expr->args, tmp) { 50 i++; 51 tmp = strip_expr(tmp); 52 if (tmp->type != EXPR_SYMBOL) 53 continue; 54 if (param_was_set(tmp)) 55 continue; 56 arg_num = get_param_num_from_sym(tmp->symbol); 57 if (arg_num < 0) 58 continue; 59 sm_msg("info: param_mapper %d => %s %d", arg_num, func, i); 60 } END_FOR_EACH_PTR(tmp); 61 } 62 check_param_mapper(int id)63void check_param_mapper(int id) 64 { 65 if (!option_info) 66 return; 67 my_id = id; 68 add_hook(&match_call, FUNCTION_CALL_HOOK); 69 } 70