2 * smatch/smatch_function_ptrs.c
4 * Copyright (C) 2013 Oracle.
6 * Licensed under the Open Software License version 1.1
11 * Track how functions are saved as various struct members or passed as
17 #include "smatch_slist.h"
21 static void match_passes_function_pointer(struct expression
*expr
)
23 struct expression
*arg
, *tmp
;
32 FOR_EACH_PTR(expr
->args
, arg
) {
35 tmp
= strip_expr(arg
);
36 if (tmp
->type
== EXPR_PREOP
&& tmp
->op
== '&')
37 tmp
= strip_expr(tmp
->unop
);
39 if (!type
|| type
->type
!= SYM_FN
)
42 called_name
= expr_to_var(expr
->fn
);
45 fn_name
= expr_to_var(tmp
);
49 snprintf(ptr_name
, sizeof(ptr_name
), "%s param %d", called_name
, i
);
50 sql_insert_function_ptr(fn_name
, ptr_name
);
53 free_string(called_name
);
54 } END_FOR_EACH_PTR(arg
);
58 static void match_function_assign(struct expression
*expr
)
60 struct expression
*right
= expr
->right
;
65 if (right
->type
== EXPR_PREOP
&& right
->op
== '&')
66 right
= strip_expr(right
->unop
);
67 if (right
->type
!= EXPR_SYMBOL
)
69 sym
= get_type(right
);
70 if (!sym
|| sym
->type
!= SYM_FN
)
73 fn_name
= expr_to_var(right
);
74 ptr_name
= get_fnptr_name(expr
->left
);
75 if (!fn_name
|| !ptr_name
)
78 sql_insert_function_ptr(fn_name
, ptr_name
);
82 free_string(ptr_name
);
85 void register_function_ptrs(int id
)
92 add_hook(&match_passes_function_pointer
, FUNCTION_CALL_HOOK
);
93 add_hook(&match_function_assign
, ASSIGNMENT_HOOK
);