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][CodeGen][BugFix] Fixes structures name collisions #844

Merged
merged 5 commits into from
Sep 16, 2024

Conversation

gitoleg
Copy link
Collaborator

@gitoleg gitoleg commented Sep 16, 2024

CIR Codegen fails to generate functions with local types with the same names. For instance, the next code :

void foo(int a, float b) {
  struct A { int x; };
  struct A loc = {a};
  {
    struct A { float y; };
    struct A loc = {b};
  }   
}

fails with on the next assertion: Unable to find record layout information for type. The problem is that we don't create record layout for the structures with equal names and CIRGenTypes::convertRecordDeclType returns the wrong type for the second struct type in the example above. This PR fixes this problem.

In the original codegen the call to Ty->setName(name) resolves name collisions and assign a proper name for the type. In our case looks like we need to use the same approach as we did for the anonymous structures, i.e. to track the used names in the builder.

Also, I fixed the struct type creation. Previously, the type was created several times - first in the CIRGenTypes::convertRecordDeclType and then in the CIRGenTypes::computeRecordLayout. This is why the indexes used by the anonymous structures naming had relatively big values and this is where the most changes on the tests come from.

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.

Nice, thanks for improving this!

@bcardosolopes bcardosolopes merged commit 2d1a4a4 into llvm:main Sep 16, 2024
6 of 7 checks passed
Hugobros3 pushed a commit to shady-gang/clangir that referenced this pull request Oct 2, 2024
CIR Codegen fails to generate functions with local types with the same
names. For instance, the next code :
```
void foo(int a, float b) {
  struct A { int x; };
  struct A loc = {a};
  {
    struct A { float y; };
    struct A loc = {b};
  }   
}
```
fails with on the next assertion: `Unable to find record layout
information for type`. The problem is that we don't create record layout
for the structures with equal names and
`CIRGenTypes::convertRecordDeclType` returns the wrong type for the
second struct type in the example above. This PR fixes this problem.

In the original codegen the call to `Ty->setName(name)` resolves name
collisions and assign a proper name for the type. In our case looks like
we need to use the same approach as we did for the anonymous structures,
i.e. to track the used names in the builder.

Also, I fixed the struct type creation. Previously, the type was created
several times - first in the `CIRGenTypes::convertRecordDeclType` and
then in the `CIRGenTypes::computeRecordLayout`. This is why the indexes
used by the anonymous structures naming had relatively big values and
this is where the most changes on the tests come from.
smeenai pushed a commit to smeenai/clangir that referenced this pull request Oct 9, 2024
CIR Codegen fails to generate functions with local types with the same
names. For instance, the next code :
```
void foo(int a, float b) {
  struct A { int x; };
  struct A loc = {a};
  {
    struct A { float y; };
    struct A loc = {b};
  }
}
```
fails with on the next assertion: `Unable to find record layout
information for type`. The problem is that we don't create record layout
for the structures with equal names and
`CIRGenTypes::convertRecordDeclType` returns the wrong type for the
second struct type in the example above. This PR fixes this problem.

In the original codegen the call to `Ty->setName(name)` resolves name
collisions and assign a proper name for the type. In our case looks like
we need to use the same approach as we did for the anonymous structures,
i.e. to track the used names in the builder.

Also, I fixed the struct type creation. Previously, the type was created
several times - first in the `CIRGenTypes::convertRecordDeclType` and
then in the `CIRGenTypes::computeRecordLayout`. This is why the indexes
used by the anonymous structures naming had relatively big values and
this is where the most changes on the tests come from.
smeenai pushed a commit to smeenai/clangir that referenced this pull request Oct 9, 2024
CIR Codegen fails to generate functions with local types with the same
names. For instance, the next code :
```
void foo(int a, float b) {
  struct A { int x; };
  struct A loc = {a};
  {
    struct A { float y; };
    struct A loc = {b};
  }
}
```
fails with on the next assertion: `Unable to find record layout
information for type`. The problem is that we don't create record layout
for the structures with equal names and
`CIRGenTypes::convertRecordDeclType` returns the wrong type for the
second struct type in the example above. This PR fixes this problem.

In the original codegen the call to `Ty->setName(name)` resolves name
collisions and assign a proper name for the type. In our case looks like
we need to use the same approach as we did for the anonymous structures,
i.e. to track the used names in the builder.

Also, I fixed the struct type creation. Previously, the type was created
several times - first in the `CIRGenTypes::convertRecordDeclType` and
then in the `CIRGenTypes::computeRecordLayout`. This is why the indexes
used by the anonymous structures naming had relatively big values and
this is where the most changes on the tests come from.
keryell pushed a commit to keryell/clangir that referenced this pull request Oct 19, 2024
CIR Codegen fails to generate functions with local types with the same
names. For instance, the next code :
```
void foo(int a, float b) {
  struct A { int x; };
  struct A loc = {a};
  {
    struct A { float y; };
    struct A loc = {b};
  }
}
```
fails with on the next assertion: `Unable to find record layout
information for type`. The problem is that we don't create record layout
for the structures with equal names and
`CIRGenTypes::convertRecordDeclType` returns the wrong type for the
second struct type in the example above. This PR fixes this problem.

In the original codegen the call to `Ty->setName(name)` resolves name
collisions and assign a proper name for the type. In our case looks like
we need to use the same approach as we did for the anonymous structures,
i.e. to track the used names in the builder.

Also, I fixed the struct type creation. Previously, the type was created
several times - first in the `CIRGenTypes::convertRecordDeclType` and
then in the `CIRGenTypes::computeRecordLayout`. This is why the indexes
used by the anonymous structures naming had relatively big values and
this is where the most changes on the tests come from.
lanza pushed a commit that referenced this pull request Nov 5, 2024
CIR Codegen fails to generate functions with local types with the same
names. For instance, the next code :
```
void foo(int a, float b) {
  struct A { int x; };
  struct A loc = {a};
  {
    struct A { float y; };
    struct A loc = {b};
  }
}
```
fails with on the next assertion: `Unable to find record layout
information for type`. The problem is that we don't create record layout
for the structures with equal names and
`CIRGenTypes::convertRecordDeclType` returns the wrong type for the
second struct type in the example above. This PR fixes this problem.

In the original codegen the call to `Ty->setName(name)` resolves name
collisions and assign a proper name for the type. In our case looks like
we need to use the same approach as we did for the anonymous structures,
i.e. to track the used names in the builder.

Also, I fixed the struct type creation. Previously, the type was created
several times - first in the `CIRGenTypes::convertRecordDeclType` and
then in the `CIRGenTypes::computeRecordLayout`. This is why the indexes
used by the anonymous structures naming had relatively big values and
this is where the most changes on the tests come from.
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.

2 participants