Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SMT] Parse SMT bitvector width as signed #8042

Merged
merged 3 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/circt/Dialect/SMT/SMTTypes.td
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def BitVectorType : SMTTypeDef<"BitVector"> {
The bit-width must be strictly greater than zero.
}];

let parameters = (ins "uint64_t":$width);
let parameters = (ins "int64_t":$width);
let assemblyFormat = "`<` $width `>`";

let genVerifyDecl = true;
Expand Down
4 changes: 2 additions & 2 deletions lib/Dialect/SMT/SMTOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,8 @@ ParseResult RepeatOp::parse(OpAsmParser &parser, OperationState &result) {
return parser.emitError(inputLoc) << "input must have bit-vector type";

// Make sure no assertions can trigger and no silent overflows can happen
// Bit-width is stored as 'uint64_t' parameter in 'BitVectorType'
const unsigned maxBw = 64;
// Bit-width is stored as 'int64_t' parameter in 'BitVectorType'
const unsigned maxBw = 63;
if (count.getActiveBits() > maxBw)
return parser.emitError(countLoc)
<< "integer must fit into " << maxBw << " bits";
Expand Down
2 changes: 1 addition & 1 deletion lib/Dialect/SMT/SMTTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ bool smt::isAnySMTValueType(Type type) {

LogicalResult
BitVectorType::verify(function_ref<InFlightDiagnostic()> emitError,
uint64_t width) {
int64_t width) {
if (width <= 0U)
return emitError() << "bit-vector must have at least a width of one";
return success();
Expand Down
15 changes: 11 additions & 4 deletions test/Dialect/SMT/bitvector-errors.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ func.func @at_least_size_one(%arg0: !smt.bv<0>) {

// -----

// expected-error @below {{bit-vector must have at least a width of one}}
func.func @positive_width(%arg0: !smt.bv<-1>) {
return
}

// -----

func.func @attr_type_and_return_type_match() {
// expected-error @below {{inferred type(s) '!smt.bv<1>' are incompatible with return type(s) of operation '!smt.bv<32>'}}
// expected-error @below {{failed to infer returned types}}
Expand Down Expand Up @@ -82,15 +89,15 @@ func.func @repeat_wrong_input_type(%arg0: !smt.bool) {
// -----

func.func @repeat_count_too_large(%arg0: !smt.bv<32>) {
// expected-error @below {{integer must fit into 64 bits}}
// expected-error @below {{integer must fit into 63 bits}}
smt.bv.repeat 18446744073709551617 times %arg0 : !smt.bv<32>
return
}

// -----

func.func @repeat_result_type_bitwidth_too_large(%arg0: !smt.bv<18446744073709551612>) {
// expected-error @below {{result bit-width (provided integer times bit-width of the input type) must fit into 64 bits}}
smt.bv.repeat 2 times %arg0 : !smt.bv<18446744073709551612>
TaoBi22 marked this conversation as resolved.
Show resolved Hide resolved
func.func @repeat_result_type_bitwidth_too_large(%arg0: !smt.bv<9223372036854775807>) {
// expected-error @below {{result bit-width (provided integer times bit-width of the input type) must fit into 63 bits}}
smt.bv.repeat 2 times %arg0 : !smt.bv<9223372036854775807>
return
}
Loading