diff options
| author | Colin Davidson <colrdavidson@gmail.com> | 2024-11-20 15:51:08 -0800 |
|---|---|---|
| committer | Colin Davidson <colrdavidson@gmail.com> | 2024-11-20 15:51:08 -0800 |
| commit | d60fb5a44e4d2e371562fd38947f8125b06bceb9 (patch) | |
| tree | 4e924ee102c2af7b30d29017ab716ed00c51ab26 /src/check_stmt.cpp | |
| parent | f3ab14b8ccb45d0fef8a96937635bdf0943ce7d6 (diff) | |
| parent | 3229f4668dfaa5f43a374bc549f42661b002699d (diff) | |
update to master
Diffstat (limited to 'src/check_stmt.cpp')
| -rw-r--r-- | src/check_stmt.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/check_stmt.cpp b/src/check_stmt.cpp index 74a9e8825..2418fcc5c 100644 --- a/src/check_stmt.cpp +++ b/src/check_stmt.cpp @@ -2600,6 +2600,23 @@ gb_internal void check_for_stmt(CheckerContext *ctx, Ast *node, u32 mod_flags) { check_expr(ctx, &o, fs->cond); if (o.mode != Addressing_Invalid && !is_type_boolean(o.type)) { error(fs->cond, "Non-boolean condition in 'for' statement"); + } else { + Ast *cond = unparen_expr(o.expr); + if (cond && cond->kind == Ast_BinaryExpr && + cond->BinaryExpr.left && cond->BinaryExpr.right && + cond->BinaryExpr.op.kind == Token_GtEq && + is_type_unsigned(type_of_expr(cond->BinaryExpr.left)) && + cond->BinaryExpr.right->tav.value.kind == ExactValue_Integer && + is_exact_value_zero(cond->BinaryExpr.right->tav.value)) { + warning(cond, "Expression is always true since unsigned numbers are always >= 0"); + } else if (cond && cond->kind == Ast_BinaryExpr && + cond->BinaryExpr.left && cond->BinaryExpr.right && + cond->BinaryExpr.op.kind == Token_LtEq && + is_type_unsigned(type_of_expr(cond->BinaryExpr.right)) && + cond->BinaryExpr.left->tav.value.kind == ExactValue_Integer && + is_exact_value_zero(cond->BinaryExpr.left->tav.value)) { + warning(cond, "Expression is always true since unsigned numbers are always >= 0"); + } } } if (fs->post != nullptr) { |