[clang] [CIR] Accept a union covered only by a bit-field's declared type (PR #222108)

Adam Smith via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 8 13:52:46 PDT 2026


================
@@ -1487,6 +1487,14 @@ BitFieldType::getABIAlignment(const mlir::DataLayout &dataLayout,
   return 1;
 }
 
+std::optional<uint64_t> BitFieldType::getDeclaredExtentInBits(
+    const mlir::DataLayout &dataLayout) const {
+  if (getFields().size() != 1)
+    return std::nullopt;
+  return dataLayout.getTypeSizeInBits(getFields().front().getDeclaredType())
----------------
adams381 wrote:

It returns nullopt for a multi-declaration unit, so `front()` only runs when there's exactly one.  A later declaration starts partway into the unit, so its declared size doesn't describe what the unit covers from bit zero.  I had considered naming this `getSoleDeclaredExtentInBits`, and can go with that if it makes it more clear.

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


More information about the cfe-commits mailing list