[all-commits] [llvm/llvm-project] 577ee9: [CIR] Fix access to bitfields inside a union (#154...

Andres-Salamanca via All-commits all-commits at lists.llvm.org
Tue Aug 19 15:43:35 PDT 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 577ee97d4e49acb171dc98afa1cccfad5f36eaa4
      https://github.com/llvm/llvm-project/commit/577ee97d4e49acb171dc98afa1cccfad5f36eaa4
  Author: Andres-Salamanca <andrealebarbaritos at gmail.com>
  Date:   2025-08-19 (Tue, 19 Aug 2025)

  Changed paths:
    M clang/lib/CIR/CodeGen/CIRGenExpr.cpp
    M clang/test/CIR/CodeGen/bitfield-union.c

  Log Message:
  -----------
  [CIR] Fix access to bitfields inside a union (#154398)

This PR fixes the access to bitfields inside a union.
Previously, we were using a `getMemberOp` to access the field, but
because it is a union, `getMemberOp` would always use index `0`.

For example, given:
```c
typedef union {
  int x;
  int y : 4;
  int z : 8;
} demo;
```
```mlir
!rec_demo = !cir.record<union "demo" {!s32i, !u8i, !u8i}>
```

In the case of:

```c
d.y = 2;
```

It would generate:

```mlir
cir.get_member %0[0] {name = "y"} : !cir.ptr<!rec_demo> -> !cir.ptr<!s32i>
```

with a return type of `!s32i`, when it should be `!u8i`.
the get_member verifier would detect that the return type does not match
the `y` member.
To fix this, we now use `bitcast` to get the start of the union.



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list