Skip to content

Commit 00b68e6

Browse files
authored
[SMT] Parse SMT bitvector width as signed (#8042)
1 parent 4a062a2 commit 00b68e6

File tree

4 files changed

+15
-8
lines changed

4 files changed

+15
-8
lines changed

include/circt/Dialect/SMT/SMTTypes.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def BitVectorType : SMTTypeDef<"BitVector"> {
3939
The bit-width must be strictly greater than zero.
4040
}];
4141

42-
let parameters = (ins "uint64_t":$width);
42+
let parameters = (ins "int64_t":$width);
4343
let assemblyFormat = "`<` $width `>`";
4444

4545
let genVerifyDecl = true;

lib/Dialect/SMT/SMTOps.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,8 @@ ParseResult RepeatOp::parse(OpAsmParser &parser, OperationState &result) {
234234
return parser.emitError(inputLoc) << "input must have bit-vector type";
235235

236236
// Make sure no assertions can trigger and no silent overflows can happen
237-
// Bit-width is stored as 'uint64_t' parameter in 'BitVectorType'
238-
const unsigned maxBw = 64;
237+
// Bit-width is stored as 'int64_t' parameter in 'BitVectorType'
238+
const unsigned maxBw = 63;
239239
if (count.getActiveBits() > maxBw)
240240
return parser.emitError(countLoc)
241241
<< "integer must fit into " << maxBw << " bits";

lib/Dialect/SMT/SMTTypes.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ bool smt::isAnySMTValueType(Type type) {
4141

4242
LogicalResult
4343
BitVectorType::verify(function_ref<InFlightDiagnostic()> emitError,
44-
uint64_t width) {
44+
int64_t width) {
4545
if (width <= 0U)
4646
return emitError() << "bit-vector must have at least a width of one";
4747
return success();

test/Dialect/SMT/bitvector-errors.mlir

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ func.func @at_least_size_one(%arg0: !smt.bv<0>) {
77

88
// -----
99

10+
// expected-error @below {{bit-vector must have at least a width of one}}
11+
func.func @positive_width(%arg0: !smt.bv<-1>) {
12+
return
13+
}
14+
15+
// -----
16+
1017
func.func @attr_type_and_return_type_match() {
1118
// expected-error @below {{inferred type(s) '!smt.bv<1>' are incompatible with return type(s) of operation '!smt.bv<32>'}}
1219
// expected-error @below {{failed to infer returned types}}
@@ -82,15 +89,15 @@ func.func @repeat_wrong_input_type(%arg0: !smt.bool) {
8289
// -----
8390

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

9097
// -----
9198

92-
func.func @repeat_result_type_bitwidth_too_large(%arg0: !smt.bv<18446744073709551612>) {
93-
// expected-error @below {{result bit-width (provided integer times bit-width of the input type) must fit into 64 bits}}
94-
smt.bv.repeat 2 times %arg0 : !smt.bv<18446744073709551612>
99+
func.func @repeat_result_type_bitwidth_too_large(%arg0: !smt.bv<9223372036854775807>) {
100+
// expected-error @below {{result bit-width (provided integer times bit-width of the input type) must fit into 63 bits}}
101+
smt.bv.repeat 2 times %arg0 : !smt.bv<9223372036854775807>
95102
return
96103
}

0 commit comments

Comments
 (0)