Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CIR][CIRGen] Achieve union's bitfields additionally. #742

Merged
merged 1 commit into from
Aug 20, 2024

Conversation

566hub
Copy link
Contributor

@566hub 566hub commented Jul 15, 2024

Achieve union's bitfields additionally.

Copy link
Member

@bcardosolopes bcardosolopes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR.

When I try to build the testcase, I get a crash in a place that doesn't seem related to the changes here:

for (const auto *Field : recordDecl->fields()) {
    if (Field->isBitField()) {
      if (Field->isZeroLengthBitField(astContext))
        continue;
      llvm_unreachable("NYI");
    }

Can you elaborate a bit more on the approach and what are you trying to achieve? @gitoleg can you also review this PR?

@DukeWJ
Copy link

DukeWJ commented Jul 17, 2024

Thanks for the PR.

When I try to build the testcase, I get a crash in a place that doesn't seem related to the changes here:

for (const auto *Field : recordDecl->fields()) {
    if (Field->isBitField()) {
      if (Field->isZeroLengthBitField(astContext))
        continue;
      llvm_unreachable("NYI");
    }

Can you elaborate a bit more on the approach and what are you trying to achieve? @gitoleg can you also review this PR?

Hi, I have met the scene that codegen union with bitfields with clangir once, and it reported 'NYI' yet. I think this PR just reuse infrastructure of struct bitfields to explain union bitfiels type. I try locally and it seems work, and new union type has carried bitfield info I think.
input

union demo {
    int x : 16;
    int y;
};

int main() {
    union demo a;

    a.x = 0;
    a.y = 1;
}

and the output

!ty_22demo22 = !cir.struct<union "demo" {!cir.int<u, 16>, !cir.int<s, 32>}>
#bfi_x = #cir.bitfield_info<name = "x", storage_type = !u16i, size = 16, offset = 0, is_signed = true>

func {
  %1 = cir.alloca !ty_22demo22, !cir.ptr<!ty_22demo22>, ["a"] {alignment = 4 : i64} loc(#loc17)
  %3 = cir.const #cir.int<0> : !s32i loc(#loc7)
  %4 = cir.cast(bitcast, %1 : !cir.ptr<!ty_22demo22>), !cir.ptr<!u16i> loc(#loc8)
  %5 = cir.set_bitfield(#bfi_x, %4 : !cir.ptr<!u16i>, %3 : !s32i) -> !s32i loc(#loc8)

  %6 = cir.const #cir.int<1> : !s32i loc(#loc9)
  %7 = cir.get_member %1[1] {name = "y"} : !cir.ptr<!ty_22demo22> -> !cir.ptr<!s32i> loc(#loc10)
  cir.store %6, %7 : !s32i, !cir.ptr<!s32i> loc(#loc19)
}

@gitoleg
Copy link
Collaborator

gitoleg commented Jul 17, 2024

looks reasonable ... though frankly speaking I didn't know that it's somehow possible (and useful!) to use bit fields in unions. But anyways, looks ok so far.

@gitoleg gitoleg closed this Jul 17, 2024
@gitoleg gitoleg reopened this Jul 17, 2024
@gitoleg
Copy link
Collaborator

gitoleg commented Jul 17, 2024

sorry, my bad, pushed wrong button

@bcardosolopes bcardosolopes changed the title [CIR]Achieve union's bitfields additionally. [CIR] Achieve union's bitfields additionally. Aug 20, 2024
@bcardosolopes bcardosolopes changed the title [CIR] Achieve union's bitfields additionally. [CIR][CIRGen] Achieve union's bitfields additionally. Aug 20, 2024
Copy link
Member

@bcardosolopes bcardosolopes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies on the delay, this LGTM. Thanks a bunch for working on this

@bcardosolopes bcardosolopes merged commit d5d122c into llvm:main Aug 20, 2024
9 checks passed
Hugobros3 pushed a commit to shady-gang/clangir that referenced this pull request Oct 2, 2024
smeenai pushed a commit to smeenai/clangir that referenced this pull request Oct 9, 2024
smeenai pushed a commit to smeenai/clangir that referenced this pull request Oct 9, 2024
keryell pushed a commit to keryell/clangir that referenced this pull request Oct 19, 2024
lanza pushed a commit that referenced this pull request Nov 5, 2024
lanza pushed a commit that referenced this pull request Mar 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants