[clang] [CIR] Include union tail pad in getTypeSizeInBits (PR #198361)

Andy Kaylor via cfe-commits cfe-commits at lists.llvm.org
Mon May 18 11:52:11 PDT 2026


================
@@ -0,0 +1,39 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir
+// RUN: FileCheck --check-prefix=CIR --input-file=%t.cir %s
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm %s -o %t-cir.ll
+// RUN: FileCheck --check-prefix=LLVM --input-file=%t-cir.ll %s
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm %s -o %t.ll
+// RUN: FileCheck --check-prefix=OGCG --input-file=%t.ll %s
+
+struct SSO {
+  char *p;
+  unsigned long len;
+  union {
+    char local[16];
+    unsigned long capacity;
+  };
+};
+
+// Inner union's tail padding must not bleed into the outer record.
+// CIR: !rec_anon{{.*}} = !cir.record<union "anon{{.*}}" padded {!cir.array<!s8i x 16>, !u64i, !cir.array<!u8i x 8>}>
----------------
andykaylor wrote:

We've got a real problem with our representation here. We've got two members that are co-located members of the union and then a padding member that is appended to whichever element is the largest/highest aligned? The padding really needs to be represented separately. Something like:

`!rec_anon{{.*}} = !cir.record<union "anon{{.*}}" padded {!cir.array<!s8i x 16>, !u64i}, padding = { !cir.array<!u8i x 8>}>`

Or maybe even

`!rec_anon{{.*}} = !cir.record<union "anon{{.*}}" padded {!cir.array<!s8i x 16>, !u64i}, paddingSize = 8>`


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


More information about the cfe-commits mailing list