2 * Copyright (C) 2018 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
19 #include "smatch_slist.h"
23 static void check_mult(struct expression
*expr
)
25 struct smatch_state
*left
, *right
;
26 int bit_found
= 0, byte_found
= 0;
29 left
= get_units(expr
->left
);
30 right
= get_units(expr
->right
);
32 if (left
== &unit_bit
|| right
== &unit_bit
)
34 if (left
== &unit_byte
|| right
== &unit_byte
)
37 if (bit_found
&& byte_found
) {
38 name
= expr_to_str(expr
);
39 sm_warning("multiplying bits * bytes '%s'", name
);
44 static void check_add_sub(struct expression
*expr
)
46 struct smatch_state
*left
, *right
;
50 type
= get_type(expr
->left
);
51 if (type
&& (type
->type
== SYM_PTR
|| type
->type
== SYM_ARRAY
))
54 left
= get_units(expr
->left
);
55 right
= get_units(expr
->right
);
57 if (!left
|| !right
|| left
== right
)
59 str
= expr_to_str(expr
);
60 sm_warning("missing conversion: '%s' '%s %s %s'", str
, left
->name
, show_special(expr
->op
), right
->name
);
64 static void match_binop_check(struct expression
*expr
)
77 static void match_condition_check(struct expression
*expr
)
79 struct smatch_state
*left
, *right
;
82 if (expr
->type
!= EXPR_COMPARE
)
85 left
= get_units(expr
->left
);
86 right
= get_units(expr
->right
);
93 str
= expr_to_str(expr
);
94 sm_msg("warn: comparing different units: '%s' '%s %s %s'", str
, left
->name
, show_special(expr
->op
), right
->name
);
98 void check_units(int id
)
105 add_hook(&match_binop_check
, BINOP_HOOK
);
106 add_hook(&match_condition_check
, CONDITION_HOOK
);