2 * Copyright 2023 Linaro Ltd.
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_extra.h"
23 static bool flip_order(struct expression
*expr
, struct expression
**left
, int *op
, struct expression
**right
)
25 /* flip everything to < */
27 expr
= strip_expr(expr
);
32 case SPECIAL_UNSIGNED_GT
:
33 case SPECIAL_UNSIGNED_GTE
:
34 *left
= strip_parens(expr
->right
);
35 *op
= flip_comparison(expr
->op
);
36 *right
= strip_parens(expr
->left
);
40 case SPECIAL_UNSIGNED_LT
:
41 case SPECIAL_UNSIGNED_LTE
:
42 *left
= strip_parens(expr
->left
);
44 *right
= strip_parens(expr
->right
);
51 static void match_condition(struct expression
*expr
)
53 struct expression
*left
, *right
;
57 if (expr
->type
!= EXPR_COMPARE
)
60 if (!flip_order(expr
, &left
, &op
, &right
))
63 if (op
!= SPECIAL_UNSIGNED_LT
&&
64 op
!= SPECIAL_UNSIGNED_LTE
)
67 if (!holds_kernel_error_codes(left
))
70 name
= expr_to_str(left
);
71 sm_warning("error code type promoted to positive: '%s'", name
);
75 void check_negative_error_code_type_promoted(int id
)
79 if (option_project
!= PROJ_KERNEL
)
82 add_hook(&match_condition
, CONDITION_HOOK
);