Repository: xdslproject/xdsl (language: python)

Issue:
dialects: Cannot parse back the LLVM dialect after passing it to MLIR
The following test cannot be parsed back after being passed to MLIR:
```
"builtin.module"() ({

  // Type tests
  "func.func"() ({
  ^0(%0 : !llvm.struct<(i32)>):
    "func.return"(%0) : (!llvm.struct<(i32)>) -> ()
  }) {"sym_name" = "struct_to_struct", "function_type" = (!llvm.struct<(i32)>) -> !llvm.struct<(i32)>, "sym_visibility" = "private"} : () -> ()

  "func.func"() ({
  ^1(%1 : !llvm.struct<(i32, i32)>):
    "func.return"(%1) : (!llvm.struct<(i32, i32)>) -> ()
  }) {"sym_name" = "struct_to_struct2", "function_type" = (!llvm.struct<(i32, i32)>) -> !llvm.struct<(i32, i32)>, "sym_visibility" = "private"} : () -> ()

  "func.func"() ({
  ^2(%2 : !llvm.struct<(!llvm.struct<(i32)>)>):
    "func.return"(%2) : (!llvm.struct<(!llvm.struct<(i32)>)>) -> ()
  }) {"sym_name" = "nested_struct_to_struct", "function_type" = (!llvm.struct<(!llvm.struct<(i32)>)>) -> !llvm.struct<(!llvm.struct<(i32)>)>, "sym_visibility" = "private"} : () -> ()

  "func.func"() ({
  ^3(%3 : !llvm.array<2 x i64>):
    %4 = "llvm.mlir.undef"() : () -> !llvm.array<1 x i32>
    "func.return"(%4) : (!llvm.array<1 x i32>) -> ()
  }) {"sym_name" = "array", "function_type" = (!llvm.array<2 x i64>) -> !llvm.array<1 x i32>, "sym_visibility" = "private"} : () -> ()

  // Op tests
  "func.func"() ({
    %5 = "arith.constant"() {"value" = 1 : i32} : () -> i32
    %6 = "llvm.mlir.undef"() : () -> !llvm.struct<(i32)>
    %7 = "llvm.insertvalue"(%6, %5) {"position" = array<i64: 0>} : (!llvm.struct<(i32)>, i32) -> !llvm.struct<(i32)>
    %8 = "llvm.extractvalue"(%7) {"position" = array<i64: 0>} : (!llvm.struct<(i32)>) -> i32
    "func.return"() : () -> ()
  }) {"sym_name" = "main", "function_type" = () -> (), "sym_visibility" = "public"} : () -> ()
```


Discussion / hints:

Fix patch:
diff --git a/xdsl/dialects/llvm.py b/xdsl/dialects/llvm.py
index 3b89dc175b..5aa46afadb 100644
--- a/xdsl/dialects/llvm.py
+++ b/xdsl/dialects/llvm.py
@@ -77,6 +77,8 @@ def _parse_llvm_type(parser: AttrParser):
         return LLVMPointerType(LLVMPointerType.parse_parameters(parser))
     if parser.parse_optional_characters("array"):
         return LLVMArrayType(LLVMArrayType.parse_parameters(parser))
+    if parser.parse_optional_characters("struct"):
+        return LLVMStructType(LLVMStructType.parse_parameters(parser))
 
 
 def parse_llvm_type(parser: AttrParser):


Test patch:
diff --git a/tests/filecheck/dialects/llvm/example.mlir b/tests/filecheck/dialects/llvm/example.mlir
index 90b9ddff18..2b30e57c64 100644
--- a/tests/filecheck/dialects/llvm/example.mlir
+++ b/tests/filecheck/dialects/llvm/example.mlir
@@ -26,6 +26,14 @@ builtin.module {
 
 // CHECK:       func.func private @nested_struct_to_struct(%0 : !llvm.struct<(!llvm.struct<(i32)>)>) -> !llvm.struct<(!llvm.struct<(i32)>)> {
 // CHECK-NEXT:    func.return %0 : !llvm.struct<(!llvm.struct<(i32)>)>
+// CHECK-NEXT:  }
+
+  func.func private @nested_struct_to_struct2(%0 : !llvm.struct<(struct<(i32)>)>) -> !llvm.struct<(struct<(i32)>)> {
+    func.return %0 : !llvm.struct<(!llvm.struct<(i32)>)>
+  }
+
+// CHECK:       func.func private @nested_struct_to_struct2(%0 : !llvm.struct<(!llvm.struct<(i32)>)>) -> !llvm.struct<(!llvm.struct<(i32)>)> {
+// CHECK-NEXT:    func.return %0 : !llvm.struct<(!llvm.struct<(i32)>)>
 // CHECK-NEXT:  }
 
   func.func private @array(%0 : !llvm.array<2 x i64>) -> !llvm.array<1 x i32> {