[FIRRTL] Type check in Cat operatnds in FIR parser (#8793)

Fix a parser crashe when cat is constructed with invalid type operands.
This commit is contained in:
Hideto Ueno 2025-07-28 18:26:56 -07:00 committed by GitHub
parent 108965f1e5
commit 7f9e66f5f5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 35 additions and 0 deletions

View File

@ -2691,11 +2691,27 @@ ParseResult FIRStmtParser::parseCatExp(Value &result) {
auto loc = getToken().getLoc();
SmallVector<Value, 3> operands;
std::optional<bool> isSigned;
if (parseListUntil(FIRToken::r_paren, [&]() -> ParseResult {
Value operand;
locationProcessor.setLoc(loc);
auto operandLoc = getToken().getLoc();
if (parseExp(operand, "expected expression in cat expression"))
return failure();
if (!type_isa<IntType>(operand.getType())) {
auto diag = emitError(loc, "all operands must be Int type");
diag.attachNote(translateLocation(operandLoc))
<< "non-integer operand is here";
return failure();
}
if (!isSigned)
isSigned = type_isa<SIntType>(operand.getType());
else if (type_isa<SIntType>(operand.getType()) != *isSigned) {
auto diag = emitError(loc, "all operands must have same signedness");
diag.attachNote(translateLocation(operandLoc))
<< "operand with different signedness is here";
return failure();
}
operands.push_back(operand);
return success();

View File

@ -1825,3 +1825,22 @@ circuit ExtModuleKnownLayerSpecMissing2ndLayerName:
layer A, bind:
; expected-error @below {{expected layer name}}
extmodule ExtModuleKnownLayerSpecMissing2ndLayerName knownlayer A,:
// -----
FIRRTL version 6.0.0
circuit CatSign:
public module CatExp:
; expected-error @below {{all operands must have same signedness}}
node n = cat(UInt<1>(0),
; expected-note @below {{operand with different signedness is here}}
SInt<1>(0))
// -----
FIRRTL version 6.0.0
circuit CatSign:
public module CatExp:
input a: UInt<1>[1]
; expected-error @below {{all operands must be Int type}}
node n = cat(UInt<1>(0),
; expected-note @below {{non-integer operand is here}}
a)