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

[RELAY] Fix segfault in pretty print when ObjectRef is null #5681

Merged
merged 2 commits into from
May 29, 2020
Merged
Show file tree
Hide file tree
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
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
10 changes: 10 additions & 0 deletions tests/python/relay/test_ir_text_printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,15 @@ def @main[A]() -> fn (A, List[A]) -> List[A] {
assert main_def_str.strip() in mod_str


def test_null_attribute():
x = relay.var("x")
y = relay.var("y")
z = relay.Function([x], y)
z = z.with_attr("TestAttribute", None)
txt = astext(z)
assert "TestAttribute=(nullptr)" in txt


if __name__ == "__main__":
do_print[0] = True
test_lstm()
Expand All @@ -262,3 +271,4 @@ def @main[A]() -> fn (A, List[A]) -> List[A] {
test_variable_name()
test_call_node_order()
test_unapplied_constructor()
test_null_attribute()