db: look up all the function pointers
[smatch.git] / check_struct_type.c
blob0982e729ad02a9bb657e7695e50c26d6d8eabade
1 /*
2 * sparse/check_struct_type.c
4 * Copyright (C) 2013 Oracle.
6 * Licensed under the Open Software License version 1.1
8 */
10 #include "smatch.h"
12 static int my_id;
14 static void match_assign(const char *fn, struct expression *expr, void *_size_arg)
16 int size_arg = PTR_INT(_size_arg);
17 struct expression *left;
18 struct expression *call;
19 struct expression *arg;
20 struct symbol *left_type;
21 struct symbol *size_type;
23 left = strip_expr(expr->left);
24 left_type = get_type(left);
25 if (!left_type || left_type->type != SYM_PTR)
26 return;
27 left_type = get_real_base_type(left_type);
28 if (!left_type || left_type->type != SYM_STRUCT)
29 return;
31 call = strip_expr(expr->right);
32 arg = get_argument_from_call_expr(call->args, size_arg);
33 if (!arg || arg->type != EXPR_SIZEOF || !arg->cast_type)
34 return;
35 size_type = arg->cast_type;
36 if (size_type->type != SYM_NODE)
37 return;
38 size_type = get_real_base_type(size_type);
39 if (size_type->type != SYM_STRUCT)
40 return;
41 if (strcmp(left_type->ident->name, size_type->ident->name) == 0)
42 return;
43 sm_msg("warn: struct type mismatch '%s vs %s'", left_type->ident->name,
44 size_type->ident->name);
48 void check_struct_type(int id)
50 my_id = id;
52 if (option_project == PROJ_KERNEL) {
53 add_function_assign_hook("kmalloc", &match_assign, INT_PTR(0));
54 add_function_assign_hook("kzalloc", &match_assign, INT_PTR(0));