xref: /illumos-gate/usr/src/tools/smatch/src/smatch_unknown_value.c (revision 8226594fdd4479be135127f43632f1f995074654)
1 /*
2  * Copyright (C) 2014 Oracle.
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 situation here is that we often need to fake an assignment but we don't
20  * know anything about the right hand side of the assignment.  We use a fake
21  * function call of &llong_ctype.  The reason for using a function call instead
22  * of a value is so we don't start storing the equivalence.
23  *
24  */
25 
26 #include "smatch.h"
27 
28 struct ident fake_assign = {
29 	.len = sizeof("fake assign"),
30 	.name = "fake assign",
31 };
32 
33 static struct symbol fake_fn_symbol = {
34 	.type = SYM_FN,
35 	.ident = &fake_assign,
36 };
37 
38 static struct symbol fake_node_symbol = {
39 	.type = SYM_NODE,
40 	.ident = &fake_assign,
41 };
42 
43 static struct expression fake_fn_expr = {
44 	.type = EXPR_SYMBOL,
45 	.ctype = &llong_ctype,
46 };
47 
48 static struct expression fake_call = {
49 	.type = EXPR_CALL,
50 	.ctype = &llong_ctype,
51 };
52 
53 static void __attribute__((constructor)) initialize_local_variables(void)
54 {
55 	fake_fn_symbol.ctype.base_type = &llong_ctype;
56 	fake_node_symbol.ctype.base_type = &fake_fn_symbol;
57 	fake_fn_expr.symbol = &fake_node_symbol;
58 	fake_fn_expr.symbol_name = &fake_assign;
59 	fake_call.fn = &fake_fn_expr;
60 }
61 
62 struct expression *unknown_value_expression(struct expression *expr)
63 {
64 	fake_fn_expr.parent = 0;
65 	fake_call.parent = 0;
66 	return &fake_call;
67 }
68 
69 int is_fake_call(struct expression *expr)
70 {
71 	return expr == &fake_call;
72 }
73