Skip to content

Commit

Permalink
[RELAY] Fix segfault in pretty print when ObjectRef is null
Browse files Browse the repository at this point in the history
Encountered when pretty printing module with function attribute equal to NullValue<ObjectRef>().

Change-Id: I2e7b304859f03038730ba9c3b9db41ebd3e1fbb5
  • Loading branch information
lhutton1 committed May 27, 2020
1 parent 07449f5 commit a40657f
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/printer/relay_text_printer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ Doc RelayTextPrinter::PrintScope(const ObjectRef& node) {
}

Doc RelayTextPrinter::PrintFinal(const ObjectRef& node) {
if (node->IsInstance<BaseFuncNode>() && !node->IsInstance<relay::FunctionNode>()) {
if (node.defined() && node->IsInstance<BaseFuncNode>() &&
!node->IsInstance<relay::FunctionNode>()) {
// Temporarily skip non-relay functions.
// TODO(tvm-team) enhance the code to work for all functions
} else if (node.as<ExprNode>()) {
Expand All @@ -105,8 +106,8 @@ Doc RelayTextPrinter::PrintFinal(const ObjectRef& node) {
}

Doc RelayTextPrinter::Print(const ObjectRef& node, bool meta, bool try_inline) {
bool is_non_relay_func =
node->IsInstance<BaseFuncNode>() && !node->IsInstance<relay::FunctionNode>();
bool is_non_relay_func = node.defined() && node->IsInstance<BaseFuncNode>() &&
!node->IsInstance<relay::FunctionNode>();
if (node.as<ExprNode>() && !is_non_relay_func) {
return PrintExpr(Downcast<Expr>(node), meta, try_inline);
} else if (node.as<TypeNode>()) {
Expand Down

0 comments on commit a40657f

Please sign in to comment.