check_unused_ret.c: ignore unreachable assignments
[smatch.git] / check_assigned_expr.c
blob512c4eddfc91adc9d3d39eb69e417aae9a25fe6b
1 /*
2 * sparse/check_assigned_expr.c
4 * Copyright (C) 2009 Dan Carpenter.
6 * Licensed under the Open Software License version 1.1
8 */
11 * This is not a check. It just saves an struct expression pointer
12 * whenever something is assigned. This can be used later on by other scripts.
15 #include "smatch.h"
16 #include "smatch_slist.h"
18 int check_assigned_expr_id;
19 static int my_id;
21 static struct smatch_state *alloc_my_state(struct expression *expr)
23 struct smatch_state *state;
24 char *name;
26 state = malloc(sizeof(*state));
27 expr = strip_expr(expr);
28 name = get_variable_from_expr_complex(expr, NULL);
29 state->name = alloc_sname(name);
30 free_string(name);
31 state->data = expr;
32 return state;
35 static void match_assignment(struct expression *expr)
37 set_state_expr(my_id, expr->left, alloc_my_state(expr->right));
40 void check_assigned_expr(int id)
42 my_id = check_assigned_expr_id = id;
43 add_hook(&match_assignment, ASSIGNMENT_HOOK);