mirror of https://github.com/llvm/circt.git
[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:
parent
108965f1e5
commit
7f9e66f5f5
|
@ -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();
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue