Skip to content

Commit

Permalink
Add test / note about $bits of large types
Browse files Browse the repository at this point in the history
  • Loading branch information
MikePopoloski committed Apr 27, 2024
1 parent a01388e commit f53dc6d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
4 changes: 3 additions & 1 deletion source/ast/builtins/QueryFuncs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ class BitsFunction : public SystemSubroutine {
width = cv.getBitstreamWidth();
}

// TODO: handle overflow of 32 bits
// Note: we convert the size down to a 32-bit result. This can result
// in (defined) overflow, which matches the behavior of all other
// tools that I tried.
return SVInt(32, width, true);
}
};
Expand Down
14 changes: 14 additions & 0 deletions tests/unittests/ast/SystemFuncTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1303,3 +1303,17 @@ endmodule
compilation.addSyntaxTree(tree);
NO_COMPILATION_ERRORS;
}

TEST_CASE("$bits of >32bit sized type") {
auto tree = SyntaxTree::fromText(R"(
logic [7:0] a [2147483647];
localparam p = $bits(a);
)");

Compilation compilation;
compilation.addSyntaxTree(tree);
NO_COMPILATION_ERRORS;

auto& p = compilation.getCompilationUnits()[0]->find<ParameterSymbol>("p");
CHECK(p.getValue().integer() == -8);
}

0 comments on commit f53dc6d

Please sign in to comment.