[clang] [CIR] Fix access to bitfields inside a union (PR #154398)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Aug 19 13:04:42 PDT 2025
================
@@ -372,9 +372,11 @@ Address CIRGenFunction::getAddrOfBitFieldStorage(LValue base,
unsigned index) {
mlir::Location loc = getLoc(field->getLocation());
cir::PointerType fieldPtr = cir::PointerType::get(fieldType);
+ auto rec = cast<cir::RecordType>(base.getAddress().getElementType());
+ if (index == 0 && rec.isUnion())
----------------
Andres-Salamanca wrote:
```diff
- loc, fieldPtr, base.getPointer(), field->getName(), index);
+ loc, fieldPtr, base.getPointer(), field->getName(), rec.isUnion() ? field->getFieldIndex() : index);
```
I changed it to use `field->getFieldIndex()`, similar to how `CIRGenFunction::emitAddrOfFieldStorage` does.
https://github.com/llvm/llvm-project/pull/154398
More information about the cfe-commits
mailing list