Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIRRTL][GrandCentral] Don't crash on missing keys, getAs. #7577

Merged
merged 1 commit into from
Sep 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions lib/Dialect/FIRRTL/Transforms/GrandCentral.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,12 @@ parseAugmentedType(ApplyState &state, DictionaryAttr augmentedType,
if (auto maybeDescription = field.get("description"))
attrs.append("description", cast<StringAttr>(maybeDescription));
attrs.append("name", name);
attrs.append("tpe", tpe.getAs<StringAttr>("class"));
auto tpeClass = tpe.getAs<StringAttr>("class");
if (!tpeClass) {
mlir::emitError(loc, "missing 'class' key in") << tpe;
return std::nullopt;
}
attrs.append("tpe", tpeClass);
elements.push_back(*eltAttr);
}
// Add an annotation that stores information necessary to construct the
Expand All @@ -972,7 +977,12 @@ parseAugmentedType(ApplyState &state, DictionaryAttr augmentedType,
// either be an actual FIRRTL ground type or a GrandCentral uninferred type.
// This can be ignored for us.
if (classBase == "GroundType") {
auto maybeTarget = refToTarget(augmentedType.getAs<DictionaryAttr>("ref"));
auto augRef = augmentedType.getAs<DictionaryAttr>("ref");
if (!augRef) {
mlir::emitError(loc, "missing 'ref' key in ") << augmentedType;
return std::nullopt;
}
auto maybeTarget = refToTarget(augRef);
if (!maybeTarget) {
mlir::emitError(loc, "Failed to parse ReferenceTarget").attachNote()
<< "See the full Annotation here: " << root;
Expand Down
Loading