[clang] [CIR] Upstream minimal support for structure types (PR #135105)

Andy Kaylor via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 10 12:17:43 PDT 2025


================
@@ -400,13 +400,126 @@ def VoidPtr : Type<
       "cir::VoidType::get($_builder.getContext()))"> {
 }
 
+//===----------------------------------------------------------------------===//
+// StructType
+//
+// The base type for all RecordDecls.
+//===----------------------------------------------------------------------===//
+
+def CIR_StructType : CIR_Type<"Struct", "struct",
+    [
+      DeclareTypeInterfaceMethods<DataLayoutTypeInterface>,
+      MutableType,
+    ]> {
+  let summary = "CIR struct type";
+  let description = [{
+    Each unique clang::RecordDecl is mapped to a `cir.struct` and any object in
+    C/C++ that has a struct type will have a `cir.struct` in CIR.
+
+    There are three possible formats for this type:
+
+     - Identified and complete structs: unique name and a known body.
+     - Identified and incomplete structs: unique name and unknown body.
+     - Anonymous structs: no name and a known body.
+
+    Identified structs are uniqued by their name, and anonymous structs are
+    uniqued by their body. This means that two anonymous structs with the same
----------------
andykaylor wrote:

This may just be stating an axiomatic fact. In practice, we seem to be giving anonymous structures a name.

https://godbolt.org/z/jfc7bT4qd

But the name isn't required by CIR, so the definition is telling you what happens if you don't have it.

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


More information about the cfe-commits mailing list