Skip to content

Commit

Permalink
Make int and float to bool conversion warnings also work inside logic…
Browse files Browse the repository at this point in the history
…al condition operators
  • Loading branch information
MikePopoloski committed Mar 8, 2024
1 parent 01eb6f6 commit 5159c17
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
5 changes: 5 additions & 0 deletions source/ast/expressions/OperatorExpressions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,11 @@ Expression& BinaryExpression::fromComponents(Expression& lhs, Expression& rhs, B
result->type = singleBitType(compilation, lt, rt);
selfDetermined(context, result->left_);
selfDetermined(context, result->right_);
if (good) {
// Call this just to get warnings about boolean conversions.
context.requireBooleanConvertible(*result->left_);
context.requireBooleanConvertible(*result->right_);
}
break;
case BinaryOperator::Equality:
case BinaryOperator::Inequality:
Expand Down
10 changes: 5 additions & 5 deletions tests/unittests/ast/AssertionTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ TEST_CASE("Local vars in assertions") {
module m;
sequence s(int i);
int j, k = j;
(i && j, j = 1, j++)[*0:1];
(i > 0 && j > 0, j = 1, j++)[*0:1];
endsequence
int baz;
Expand Down Expand Up @@ -373,7 +373,7 @@ TEST_CASE("Local vars default values") {
module m;
sequence s(i);
int j, k = j, l = i, m = baz;
(i && j, j = 1, j++)[*1:2];
(i > 0 && j > 0, j = 1, j++)[*1:2];
endsequence
assert property (s(3));
endmodule
Expand Down Expand Up @@ -837,7 +837,7 @@ module m;
sequence sub_seq2(local inout int lv);
(a ##1 !a, lv += data_in)
##1 !b[*0:$] ##1 b && (data_out == lv);
##1 !b[*0:$] ##1 b > 0 && (data_out == lv);
endsequence
sequence seq2;
Expand Down Expand Up @@ -990,7 +990,7 @@ module m;
wire clk;
property p;
int a;
bit a;
@(posedge clk) disable iff (a || s.matched) 1;
endproperty
endmodule
Expand All @@ -1014,7 +1014,7 @@ module m;
wire clk;
property p;
int a;
bit a;
@(posedge clk) accept_on (a || s.matched) 1;
endproperty
endmodule
Expand Down
5 changes: 4 additions & 1 deletion tests/unittests/ast/WarningTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,7 @@ module m;
int i;
initial if (i + 2) begin end
initial if (i || r) begin end
// These don't warn
initial if (i >> 2) begin end
Expand All @@ -765,9 +766,11 @@ endmodule
compilation.addSyntaxTree(tree);

auto& diags = compilation.getAllDiagnostics();
REQUIRE(diags.size() == 2);
REQUIRE(diags.size() == 4);
CHECK(diags[0].code == diag::FloatBoolConv);
CHECK(diags[1].code == diag::IntBoolConv);
CHECK(diags[2].code == diag::IntBoolConv);
CHECK(diags[3].code == diag::FloatBoolConv);
}

TEST_CASE("Useless cast warnings") {
Expand Down

0 comments on commit 5159c17

Please sign in to comment.