buf_size: fix handling of 1 element arrays
[smatch.git] / smatch_mtag_map.c
blob8384a9908f16caf29816fda8cf3f308266ee3151
1 /*
2 * Copyright (C) 2017 Oracle. All rights reserved.
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 * This basically stores when a pointer is stored as a struct member.
23 #include "smatch.h"
24 #include "smatch_slist.h"
25 #include "smatch_extra.h"
27 static int my_id;
29 static void match_assign(struct expression *expr)
31 struct expression *left, *right;
32 mtag_t left_tag, right_tag;
33 int offset;
35 if (expr->op != '=')
36 return;
38 left = strip_expr(expr->left);
39 right = strip_expr(expr->right);
41 if (left->type != EXPR_DEREF)
42 return;
44 offset = get_member_offset_from_deref(left);
45 if (offset < 0)
46 return;
48 if (!get_mtag(left->deref, &left_tag))
49 return;
50 if (!get_mtag(right, &right_tag))
51 return;
53 sql_insert_mtag_map(right_tag, -offset, left_tag);
56 void register_mtag_map(int id)
58 my_id = id;
60 add_hook(&match_assign, ASSIGNMENT_HOOK);
61 add_hook(&match_assign, GLOBAL_ASSIGNMENT_HOOK);