Skip to content

Conversation

@tommymcm
Copy link
Collaborator

@tommymcm tommymcm commented Aug 4, 2025

Implemented NYI handling for cir::ConstRecordAttr in CIR CodeGen global replacement.

Refactored existing support for cir::ConstArrayAttr to share duplicate code between the two.

newElements, mlir::cast<cir::ArrayType>(oldArray.getType()));
}
if (auto oldRecord = mlir::dyn_cast<cir::ConstRecordAttr>(oldInit)) {
mlir::ArrayAttr newMembers = getNewInitElements(oldRecord.getMembers());
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it possible to get here with anything other than a zero initializer? I'm having a hard time mapping between your test and the behavior here.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe I misunderstood, but this path comes from replaceGlobal, which just checks if there's an initial value, given this check goes for the top level initial value, looks like it's ok?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I did some manual fuzzing to test this, it looks like you can only get here with a tentative array initialization (zero-initialized array of length 1).
If the test in globals.c is modified in either of the following ways, then the path isn't exercised:

struct A {
  signed *x;
} tentativeF[10]; // sized array
signed glob;
struct A {
  signed *x;
} tentativeF[] = {&glob}; // initialized

Copy link
Collaborator

Choose a reason for hiding this comment

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

I thought that might be the case. The code seems to be handling general initializer possibilities, which I guess is OK, but I also couldn't find a way to get here with anything other than a zero initializer.

newElements, mlir::cast<cir::ArrayType>(oldArray.getType()));
}
if (auto oldRecord = mlir::dyn_cast<cir::ConstRecordAttr>(oldInit)) {
mlir::ArrayAttr newMembers = getNewInitElements(oldRecord.getMembers());
Copy link
Member

Choose a reason for hiding this comment

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

Maybe I misunderstood, but this path comes from replaceGlobal, which just checks if there's an initial value, given this check goes for the top level initial value, looks like it's ok?

Copy link
Collaborator

@andykaylor andykaylor left a comment

Choose a reason for hiding this comment

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

lgtm if @bcardosolopes is satisfied

newElements, mlir::cast<cir::ArrayType>(oldArray.getType()));
}
if (auto oldRecord = mlir::dyn_cast<cir::ConstRecordAttr>(oldInit)) {
mlir::ArrayAttr newMembers = getNewInitElements(oldRecord.getMembers());
Copy link
Collaborator

Choose a reason for hiding this comment

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

I thought that might be the case. The code seems to be handling general initializer possibilities, which I guess is OK, but I also couldn't find a way to get here with anything other than a zero initializer.

@bcardosolopes bcardosolopes merged commit 714fee3 into llvm:main Aug 7, 2025
6 of 9 checks passed
terapines-osc-cir pushed a commit to Terapines/clangir that referenced this pull request Sep 2, 2025
…Attr` (llvm#1778)

Implemented NYI handling for `cir::ConstRecordAttr` in CIR CodeGen
global replacement.

Refactored existing support for `cir::ConstArrayAttr` to share duplicate
code between the two.
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.

3 participants