Skip to content

Commit

Permalink
[FIRRTL][InferWidths] Fix handling of non-base ports in instances. (l…
Browse files Browse the repository at this point in the history
…lvm#5791)

Don't crash if encounter non-base type on instance op with
uninferred widths.
  • Loading branch information
dtzSiFive authored Aug 7, 2023
1 parent a7f4e0e commit 12fc549
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
10 changes: 6 additions & 4 deletions lib/Dialect/FIRRTL/Transforms/InferWidths.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1598,12 +1598,14 @@ LogicalResult InferenceMapping::mapOperation(Operation *op) {

auto fml = cast<FModuleLike>(&*refdModule);
auto ports = fml.getPorts();
for (auto &port : ports)
if (type_cast<FIRRTLBaseType>(port.type).hasUninferredWidth()) {
for (auto &port : ports) {
auto baseType = getBaseType(port.type);
if (baseType && baseType.hasUninferredWidth()) {
diag.attachNote(op.getLoc()) << "Port: " << port.name;
if (!type_cast<FIRRTLBaseType>(port.type).isGround())
diagnoseUninferredType(diag, port.type, port.name.getValue());
if (!baseType.isGround())
diagnoseUninferredType(diag, baseType, port.name.getValue());
}
}

diag.attachNote(op.getLoc())
<< "Only non-extern FIRRTL modules may contain unspecified "
Expand Down
27 changes: 18 additions & 9 deletions test/Dialect/FIRRTL/infer-widths-errors.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,25 @@ firrtl.circuit "Foo" {
// -----
firrtl.circuit "Foo" {
// expected-note @+1 {{Module `Bar` defined here:}}
firrtl.extmodule @Bar(in in: !firrtl.uint,
out out: !firrtl.bundle<a : uint, b: uint<4>, c: vector<bundle<c: uint>,4>>)
firrtl.extmodule @Bar(
in in: !firrtl.uint,
out out: !firrtl.bundle<a : uint, b: uint<4>, c: vector<bundle<c: uint>,4>>,
out ref: !firrtl.rwprobe<bundle<a: uint>>,
out string: !firrtl.string)
firrtl.module @Foo(in %in: !firrtl.uint<42>, out %out: !firrtl.bundle<a : uint, b: uint<4>, c: vector<bundle<c: uint>,4>>) {
// expected-error @+6 {{extern module `Bar` has ports of uninferred width}}
// expected-note @+5 {{Port: "in"}}
// expected-note @+4 {{Port: "out"}}
// expected-note @+3 {{Field: "out.a"}}
// expected-note @+2 {{Field: "out.c[].c"}}
// expected-note @+1 {{Only non-extern FIRRTL modules may contain unspecified widths to be inferred automatically.}}
%inst_in, %inst_out = firrtl.instance inst @Bar(in in: !firrtl.uint, out out: !firrtl.bundle<a : uint, b: uint<4>, c: vector<bundle<c: uint>,4>>)
// expected-error @below {{extern module `Bar` has ports of uninferred width}}
// expected-note @below {{Port: "in"}}
// expected-note @below {{Port: "out"}}
// expected-note @below {{Field: "out.a"}}
// expected-note @below {{Field: "out.c[].c"}}
// expected-note @below {{Port: "ref"}}
// expected-note @below {{Field: "ref.a"}}
// expected-note @below {{Only non-extern FIRRTL modules may contain unspecified widths to be inferred automatically.}}
%inst_in, %inst_out, %inst_ref, %inst_string = firrtl.instance inst @Bar(
in in: !firrtl.uint,
out out: !firrtl.bundle<a : uint, b: uint<4>, c: vector<bundle<c: uint>,4>>,
out ref: !firrtl.rwprobe<bundle<a: uint>>,
out string: !firrtl.string)
firrtl.connect %inst_in, %in : !firrtl.uint, !firrtl.uint<42>
firrtl.connect %out, %inst_out : !firrtl.bundle<a : uint, b: uint<4>, c: vector<bundle<c: uint>,4>>, !firrtl.bundle<a : uint, b: uint<4>, c: vector<bundle<c: uint>,4>>
}
Expand Down

0 comments on commit 12fc549

Please sign in to comment.