Skip to content

Commit

Permalink
core: fix attributes to func outputs (#3675)
Browse files Browse the repository at this point in the history
There is a bug when we want to print a single output parameter with
attributes - it still needs to be enclosed in braces.
  • Loading branch information
mamanain authored Dec 24, 2024
1 parent 6411225 commit 9094df5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
10 changes: 10 additions & 0 deletions tests/filecheck/dialects/func/func_ops.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,14 @@ builtin.module {
// CHECK-NEXT: %r1, %r2 = "test.op"() : () -> (f32, f32)
// CHECK-NEXT: func.return %r1, %r2 : f32, f32
// CHECK-NEXT: }

func.func @output_attribute_single() -> (f32 {dialect.a = 0 : i32}) {
%r1 = "test.op"() : () -> (f32)
return %r1: f32
}

// CHECK: func.func @output_attribute_single() -> (f32 {"dialect.a" = 0 : i32}) {
// CHECK-NEXT: %r1 = "test.op"() : () -> f32
// CHECK-NEXT: func.return %r1 : f32
// CHECK-NEXT: }
}
4 changes: 2 additions & 2 deletions xdsl/dialects/utils/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def print_func_op_like(
printer.print(") ")
if function_type.outputs:
printer.print("-> ")
if len(function_type.outputs) > 1:
if len(function_type.outputs) > 1 or res_attrs is not None:
printer.print("(")
if res_attrs is not None:
printer.print_list(
Expand All @@ -72,7 +72,7 @@ def print_func_op_like(
)
else:
printer.print_list(function_type.outputs, printer.print_attribute)
if len(function_type.outputs) > 1:
if len(function_type.outputs) > 1 or res_attrs is not None:
printer.print(")")
printer.print(" ")
else:
Expand Down

0 comments on commit 9094df5

Please sign in to comment.