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] Improve emission for array of unions #1236

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

ChuanqiXu9
Copy link
Member

Close #1185

The patch itself seems slightly ad-hoc. As the issue tracked by #1178, the fundamental solution may be to introduce two type systems to solve the inconsistent semantics for Union between LLVM IR and CIR. This will be great to handle other inconsistent semantics between LLVM IR and CIR if any.

Back to the patch itself, although the code looks not good initially to me too. But I feel it may be a good workaround since clang/test/CIR/Lowering/union-array.c is an example for array of unions directly and clang/test/CIR/Lowering/nested-union-array.c gives an example for array of unions indirectly (array of structs which contain unions). So I feel we've already covered all the cases.

And generally it should be good to use some simple and solid workaround before we introduce the formal full solution.

Close llvm#1185

The patch itself seems slightly ad-hoc. As the issue tracked by
llvm#1178, the fundamental solution
may be to introduce two type systems to solve the inconsistent semantics
for Union between LLVM IR and CIR. This will be great to handle other
inconsistent semantics between LLVM IR and CIR if any.

Back to the patch itself, although the code looks not good initially to
me too. But I feel it may be a good workaround since
clang/test/CIR/Lowering/union-array.c is an example for array of unions
directly and clang/test/CIR/Lowering/nested-union-array.c gives an
example for array of unions indirectly (array of structs which contain
unions). So I feel we've already covered all the cases.

And generally it should be good to use some simple and solid workaround
before we introduce the formal full solution.
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.

I think it's fine to have a workaround here, as we collect those it provides us more testcases we should not regress when going for the more general approach.

clang/test/CIR/Lowering/union-array.c Outdated Show resolved Hide resolved
clang/lib/CIR/CodeGen/CIRGenExprConst.cpp Show resolved Hide resolved
@bcardosolopes bcardosolopes changed the title [CIR] [CIRGen] Handle CIR Gen for array of unions [CIR][CIRGen] Handle CIR Gen for array of unions Dec 17, 2024
@bcardosolopes bcardosolopes changed the title [CIR][CIRGen] Handle CIR Gen for array of unions [CIR][CIRGen] Improve emission for array of unions Dec 17, 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.

A few more nits and good to go

clang/lib/CIR/CodeGen/CIRGenExprConst.cpp Outdated Show resolved Hide resolved
clang/lib/CIR/CodeGen/CIRGenExprConst.cpp Outdated Show resolved Hide resolved
// lower to LLVM IR (or anyother dialects) with the proper type.
//
// (Although the idea to make CIR's type system self contained and generate
// LLVM's
Copy link
Member

Choose a reason for hiding this comment

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

indentation for this paragraph is odd

Copy link
Member Author

Choose a reason for hiding this comment

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

It was formatted by clang-format ..

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.

Lowering to LLVM fails for constant array of unions with unequal initializer types
2 participants