fixup_kernel: hard code __spi_sync() returns.
[smatch.git] / smatch_address.c
blob6f9f922aa9540157a3c6ebf4b92fc58bd7837f43
1 /*
2 * Copyright (C) 2015 Oracle.
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
18 #include "smatch.h"
19 #include "smatch_slist.h"
20 #include "smatch_extra.h"
22 static bool is_non_null_array(struct expression *expr)
24 struct symbol *type;
25 struct symbol *sym;
26 struct symbol *tmp;
27 char *name;
28 int i;
30 type = get_type(expr);
31 if (!type || type->type != SYM_ARRAY)
32 return 0;
33 if (expr->type == EXPR_SYMBOL)
34 return 1;
35 if (implied_not_equal(expr, 0))
36 return 1;
38 /* verify that it's not the first member of the struct */
39 if (expr->type != EXPR_DEREF || !expr->member)
40 return 0;
41 name = expr_to_var_sym(expr, &sym);
42 free_string(name);
43 if (!name || !sym)
44 return 0;
45 type = get_real_base_type(sym);
46 if (!type || type->type != SYM_PTR)
47 return 0;
48 type = get_real_base_type(type);
49 if (type->type != SYM_STRUCT)
50 return 0;
52 i = 0;
53 FOR_EACH_PTR(type->symbol_list, tmp) {
54 i++;
55 if (!tmp->ident)
56 continue;
57 if (strcmp(expr->member->name, tmp->ident->name) == 0) {
58 if (i == 1)
59 return 0;
60 return 1;
62 } END_FOR_EACH_PTR(tmp);
64 return 0;
67 int get_address_rl(struct expression *expr, struct range_list **rl)
69 if (is_non_null_array(expr)) {
70 *rl = alloc_rl(array_min_sval, array_max_sval);
71 return 1;
74 return 0;