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

Move struct field name from callsite to type #150

Open
sitio-couto opened this issue Jul 3, 2023 · 2 comments
Open

Move struct field name from callsite to type #150

sitio-couto opened this issue Jul 3, 2023 · 2 comments

Comments

@sitio-couto
Copy link
Collaborator

sitio-couto commented Jul 3, 2023

This is great, glad you beat me to it, we needed this to happen sooner or later.

Brain dump: keeping the name at the "callsite" is a bit silly, we should probably store these names into the cir.struct themselves and when we create a pretty printer for struct_element_addr we could print the names for convenience, by just looking at the type.

Originally posted by @bcardosolopes in #148 (review)

@sitio-couto sitio-couto changed the title Move struct filed name from callsite to type Move struct field name from callsite to type Jul 3, 2023
@PragmaTwice
Copy link
Contributor

It seems that struct_element_addr has been renamed to get_member, but the issue still exists.

If no one has already started working on it, I will look into it soon : )

@PragmaTwice
Copy link
Contributor

PragmaTwice commented May 19, 2024

I have checked the issue and it appears challenging to handle when dealing with bitfields.

The bitfield information in cir.struct has already been erased, making it difficult to map each field type in cir.struct to the data member's name.

It seems to me that one possible way is to maintain data member types in cir.struct with bitfield information, and transform it to the current form when dumping LLVM IR, e.g.

// SOURCE CODE
struct A {
  int a;
  int b : 1;
  int c : 1;
};

// AS IS:
!ty_22A22 = !cir.struct<struct "A" {!cir.int<s, 32>, !cir.int<u, 8>}

// TO BE: (not real CIR code)
!ty_22A22 = !cir.struct<struct "A" {!cir.int<s, 32> a, !cir.int<s, 32> BITFIELD(1) b, !cir.int<s, 32> BITFIELD(1) c}

But in this way, the handling of memory location / memory layout in CIR will be a bit tricky.

Another way might be to keep the current approach and put the data member name in cir.get_member.

Any suggestions for this? 🤔 cc @bcardosolopes @sitio-couto

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

No branches or pull requests

2 participants