[Mlir-commits] [mlir] [mlir][EmitC] Create a pass to add a reflection map to a class (PR #205464)

ioana ghiban llvmlistbot at llvm.org
Tue Jul 14 02:39:32 PDT 2026


================
@@ -55,4 +56,73 @@ emitc.class @actionClass {
 // CHECK-NEXT:      %{{.*}} = get_field @fieldName0 : !emitc.array<1xf32>
 // CHECK-NEXT:      return
 // CHECK-NEXT:    }
+// CHECK-NEXT:  }
+
+// -----
+
+/// Test that the pass leaves IR unchanged if fields don't have any attributes
+
+emitc.class @actionClassNoAttrs {
+  // expected-error @below {{FieldOp must have a dictionary attribute named 'emitc.field_ref' with an array containing a string attribute}}
+  emitc.field @fieldName0 : !emitc.array<1xf32>
+  emitc.func @"operator()"() {
+    return
+  }
+}
+
+// CHECK-LABEL: emitc.class @actionClassNoAttrs {
+// CHECK-NEXT:    emitc.field @fieldName0 : !emitc.array<1xf32>
+// CHECK-NEXT:    emitc.func @"operator()"() {
+// CHECK-NEXT:      return
+// CHECK-NEXT:    }
+// CHECK-NEXT:  }
+
+// -----
+
+/// Test that the pass leaves IR unchanged if the ClassOp doesn't have any fields
+
+emitc.class @actionClassNoFields {
+  emitc.func @"operator()"() {
+    return
+  }
+}
+
+// CHECK-LABEL: emitc.class @actionClassNoFields {
+// CHECK-NEXT:    emitc.func @"operator()"() {
+// CHECK-NEXT:      return
+// CHECK-NEXT:    }
+// CHECK-NEXT:  }
+
+// -----
+
+/// Test that the pass returns with a match failure if the ClassOp doesn't have
+/// a FunctionOp named operator()
+
+// expected-error @below {{ClassOp must contain a function named 'operator()' to add reflection map}}
----------------
ioghiban wrote:

[nit]: move tests with diagnostic verifiers to a different file

https://github.com/llvm/llvm-project/pull/205464


More information about the Mlir-commits mailing list