1*1f5207b7SJohn Levon /*
2*1f5207b7SJohn Levon  * Copyright (C) 2010 Dan Carpenter.
3*1f5207b7SJohn Levon  *
4*1f5207b7SJohn Levon  * This program is free software; you can redistribute it and/or
5*1f5207b7SJohn Levon  * modify it under the terms of the GNU General Public License
6*1f5207b7SJohn Levon  * as published by the Free Software Foundation; either version 2
7*1f5207b7SJohn Levon  * of the License, or (at your option) any later version.
8*1f5207b7SJohn Levon  *
9*1f5207b7SJohn Levon  * This program is distributed in the hope that it will be useful,
10*1f5207b7SJohn Levon  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11*1f5207b7SJohn Levon  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12*1f5207b7SJohn Levon  * GNU General Public License for more details.
13*1f5207b7SJohn Levon  *
14*1f5207b7SJohn Levon  * You should have received a copy of the GNU General Public License
15*1f5207b7SJohn Levon  * along with this program; if not, see http://www.gnu.org/copyleft/gpl.txt
16*1f5207b7SJohn Levon  */
17*1f5207b7SJohn Levon 
18*1f5207b7SJohn Levon #include "smatch.h"
19*1f5207b7SJohn Levon 
20*1f5207b7SJohn Levon static int my_id;
21*1f5207b7SJohn Levon 
match_stmt(struct statement * stmt)22*1f5207b7SJohn Levon static void match_stmt(struct statement *stmt)
23*1f5207b7SJohn Levon {
24*1f5207b7SJohn Levon 	struct expression *expr;
25*1f5207b7SJohn Levon 
26*1f5207b7SJohn Levon 	if (stmt->type != STMT_EXPRESSION)
27*1f5207b7SJohn Levon 		return;
28*1f5207b7SJohn Levon 	expr = stmt->expression;
29*1f5207b7SJohn Levon 	if (!expr)
30*1f5207b7SJohn Levon 		return;
31*1f5207b7SJohn Levon 	switch(expr->type) {
32*1f5207b7SJohn Levon 	case EXPR_PREOP:
33*1f5207b7SJohn Levon 		if (expr->op == '!')
34*1f5207b7SJohn Levon 			break;
35*1f5207b7SJohn Levon 		if (expr->op == '~')
36*1f5207b7SJohn Levon 			break;
37*1f5207b7SJohn Levon 	case EXPR_POSTOP:
38*1f5207b7SJohn Levon 	case EXPR_STATEMENT:
39*1f5207b7SJohn Levon 	case EXPR_ASSIGNMENT:
40*1f5207b7SJohn Levon 	case EXPR_CALL:
41*1f5207b7SJohn Levon 	case EXPR_CONDITIONAL:
42*1f5207b7SJohn Levon 	case EXPR_SELECT:
43*1f5207b7SJohn Levon 	case EXPR_CAST:
44*1f5207b7SJohn Levon 	case EXPR_FORCE_CAST:
45*1f5207b7SJohn Levon 	case EXPR_COMMA:
46*1f5207b7SJohn Levon 		return;
47*1f5207b7SJohn Levon 	}
48*1f5207b7SJohn Levon 	if (in_expression_statement())
49*1f5207b7SJohn Levon 		return;
50*1f5207b7SJohn Levon 	sm_warning("statement has no effect %d", expr->type);
51*1f5207b7SJohn Levon }
52*1f5207b7SJohn Levon 
check_no_effect(int id)53*1f5207b7SJohn Levon void check_no_effect(int id)
54*1f5207b7SJohn Levon {
55*1f5207b7SJohn Levon 	my_id = id;
56*1f5207b7SJohn Levon 	add_hook(&match_stmt, STMT_HOOK);
57*1f5207b7SJohn Levon }
58