mirror of https://github.com/llvm/circt.git
[HW] Fix crash when error encountered parsing hw.array. (#7578)
Fix checking of OptionalParseResult, having value does not mean that the parsing succeeded. Add test. Found via fuzzing.
This commit is contained in:
parent
f074d91fea
commit
38f45e1be1
|
@ -558,10 +558,16 @@ static ParseResult parseHWArray(AsmParser &p, Attribute &dim, Type &inner) {
|
|||
uint64_t dimLiteral;
|
||||
auto int64Type = p.getBuilder().getIntegerType(64);
|
||||
|
||||
if (auto res = p.parseOptionalInteger(dimLiteral); res.has_value())
|
||||
dim = p.getBuilder().getI64IntegerAttr(dimLiteral);
|
||||
else if (!p.parseOptionalAttribute(dim, int64Type).has_value())
|
||||
if (auto res = p.parseOptionalInteger(dimLiteral); res.has_value()) {
|
||||
if (failed(*res))
|
||||
return failure();
|
||||
dim = p.getBuilder().getI64IntegerAttr(dimLiteral);
|
||||
} else if (auto res64 = p.parseOptionalAttribute(dim, int64Type);
|
||||
res64.has_value()) {
|
||||
if (failed(*res64))
|
||||
return failure();
|
||||
} else
|
||||
return p.emitError(p.getNameLoc(), "expected integer");
|
||||
|
||||
if (!isa<IntegerAttr, ParamExprAttr, ParamDeclRefAttr>(dim)) {
|
||||
p.emitError(p.getNameLoc(), "unsupported dimension kind in hw.array");
|
||||
|
|
|
@ -501,3 +501,8 @@ hw.module @Foo () {
|
|||
hw.instance_choice "inst" option "foo" @DoesNotExist () -> ()
|
||||
}
|
||||
|
||||
// -----
|
||||
|
||||
// Don't crash if hw.array attribute fails to parse as integer
|
||||
// expected-error @below {{floating point value not valid for specified type}}
|
||||
hw.module @arrayTypeError(in %in: !hw.array<44.44axi0>) { }
|
||||
|
|
Loading…
Reference in New Issue