Skip to content

[CIR][CodeGen][Bugfix] generate field index with respect to layout #263

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

Merged
merged 1 commit into from
Sep 19, 2023

Conversation

gitoleg
Copy link
Collaborator

@gitoleg gitoleg commented Sep 18, 2023

There is a bug in the code generation: the field index for the GetMemberOp is taken from the FieldDecl, with no respect to the record layout. One of the manifestation of the bug is the wrong index generated for a field in a derived class that does not take into the account the instance of the base class (that has index 0).

You can take a look at the example in test/CIR/CodeGen/derived-to-base.cpp, i.e. the current test is not the correct one

// CHECK-DAG: !ty_22C23A3ALayer22 = !cir.struct<class "C2::Layer" {!ty_22C13A3ALayer22, !cir.ptr<!ty_22C222>
// CHECK-DAG: !ty_22C33A3ALayer22 = !cir.struct<struct "C3::Layer" {!ty_22C23A3ALayer22

// CHECK: cir.func @_ZN2C35Layer10InitializeEv

// CHECK:  cir.scope {
// CHECK:    %2 = cir.base_class_addr(%1 : cir.ptr <!ty_22C33A3ALayer22>) -> cir.ptr <!ty_22C23A3ALayer22>
// CHECK:    %3 = cir.get_member %2[0] {name = "m_C1"} : !cir.ptr<!ty_22C23A3ALayer22> -> !cir.ptr<!cir.ptr<!ty_22C222>>

As one can see, the result (of ptr type to !ty_22C222 ) must have the index 1 in the corresponded struct ty_22C23A3ALayer22.

Basically the same is done in the clang/CodeGen/CGExpr.cpp, so we don't invent something new here.

Note, this fix doesn't affect anything related to the usage of buildPreserveStructAccess where the field->getFieldIndex() is used.

Copy link
Contributor

@htyu htyu left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for the fix!

@bcardosolopes
Copy link
Member

Awesome, LGTM.

Btw, what about other uses of getFieldIndex() in the CIR codebase, do any other of them need to be patched too?

@bcardosolopes bcardosolopes merged commit cb8f2a0 into llvm:main Sep 19, 2023
@gitoleg
Copy link
Collaborator Author

gitoleg commented Sep 20, 2023

@bcardosolopes I take a look at, it's not clear from the first glance if they need or need not

bcardosolopes pushed a commit that referenced this pull request Sep 26, 2023
#270)

This is a minor fix similar to the one introduced in #263.
Basically, all calls to the `buildLValueForFieldInitialization` are even
with the origin codegen `emitLValueForFieldInitialization` calls, i.e.
the field index is calculated from the record layout, but not from the
decl `field->getFieldIndex()`.

Added just one test, because looks like we need to implement some `NYI`
features first to test another places e.g. in `CIRGenExprAgg.cpp`,
though I could miss something.

Anyway, given the original codegen doesn't use `getFieldIndex` in these
places, we also should not.

All the remaining usages of `getFieldIndex` are ok.
lanza pushed a commit that referenced this pull request Oct 27, 2023
)

There is a bug in the code generation: the field index for the
`GetMemberOp` is taken from the `FieldDecl`, with no respect to the
record layout. One of the manifestation of the bug is the wrong index
generated for a field in a derived class that does not take into the
account the instance of the base class (that has index 0).

You can take a look at the example in
`test/CIR/CodeGen/derived-to-base.cpp`, i.e. the current test is not the
correct one
```
// CHECK-DAG: !ty_22C23A3ALayer22 = !cir.struct<class "C2::Layer" {!ty_22C13A3ALayer22, !cir.ptr<!ty_22C222>
// CHECK-DAG: !ty_22C33A3ALayer22 = !cir.struct<struct "C3::Layer" {!ty_22C23A3ALayer22

// CHECK: cir.func @_ZN2C35Layer10InitializeEv

// CHECK:  cir.scope {
// CHECK:    %2 = cir.base_class_addr(%1 : cir.ptr <!ty_22C33A3ALayer22>) -> cir.ptr <!ty_22C23A3ALayer22>
// CHECK:    %3 = cir.get_member %2[0] {name = "m_C1"} : !cir.ptr<!ty_22C23A3ALayer22> -> !cir.ptr<!cir.ptr<!ty_22C222>>
```
As one can see, the result (of ptr type to `!ty_22C222` ) must have the
index `1` in the corresponded struct `ty_22C23A3ALayer22`.

Basically the same is done in the `clang/CodeGen/CGExpr.cpp`, so we
don't invent something new here.

Note, this fix doesn't affect anything related to the usage of
`buildPreserveStructAccess` where the `field->getFieldIndex()` is used.
lanza pushed a commit that referenced this pull request Oct 27, 2023
#270)

This is a minor fix similar to the one introduced in #263.
Basically, all calls to the `buildLValueForFieldInitialization` are even
with the origin codegen `emitLValueForFieldInitialization` calls, i.e.
the field index is calculated from the record layout, but not from the
decl `field->getFieldIndex()`.

Added just one test, because looks like we need to implement some `NYI`
features first to test another places e.g. in `CIRGenExprAgg.cpp`,
though I could miss something.

Anyway, given the original codegen doesn't use `getFieldIndex` in these
places, we also should not.

All the remaining usages of `getFieldIndex` are ok.
lanza pushed a commit that referenced this pull request Dec 20, 2023
)

There is a bug in the code generation: the field index for the
`GetMemberOp` is taken from the `FieldDecl`, with no respect to the
record layout. One of the manifestation of the bug is the wrong index
generated for a field in a derived class that does not take into the
account the instance of the base class (that has index 0).

You can take a look at the example in
`test/CIR/CodeGen/derived-to-base.cpp`, i.e. the current test is not the
correct one
```
// CHECK-DAG: !ty_22C23A3ALayer22 = !cir.struct<class "C2::Layer" {!ty_22C13A3ALayer22, !cir.ptr<!ty_22C222>
// CHECK-DAG: !ty_22C33A3ALayer22 = !cir.struct<struct "C3::Layer" {!ty_22C23A3ALayer22

// CHECK: cir.func @_ZN2C35Layer10InitializeEv

// CHECK:  cir.scope {
// CHECK:    %2 = cir.base_class_addr(%1 : cir.ptr <!ty_22C33A3ALayer22>) -> cir.ptr <!ty_22C23A3ALayer22>
// CHECK:    %3 = cir.get_member %2[0] {name = "m_C1"} : !cir.ptr<!ty_22C23A3ALayer22> -> !cir.ptr<!cir.ptr<!ty_22C222>>
```
As one can see, the result (of ptr type to `!ty_22C222` ) must have the
index `1` in the corresponded struct `ty_22C23A3ALayer22`.

Basically the same is done in the `clang/CodeGen/CGExpr.cpp`, so we
don't invent something new here.

Note, this fix doesn't affect anything related to the usage of
`buildPreserveStructAccess` where the `field->getFieldIndex()` is used.
lanza pushed a commit that referenced this pull request Dec 20, 2023
#270)

This is a minor fix similar to the one introduced in #263.
Basically, all calls to the `buildLValueForFieldInitialization` are even
with the origin codegen `emitLValueForFieldInitialization` calls, i.e.
the field index is calculated from the record layout, but not from the
decl `field->getFieldIndex()`.

Added just one test, because looks like we need to implement some `NYI`
features first to test another places e.g. in `CIRGenExprAgg.cpp`,
though I could miss something.

Anyway, given the original codegen doesn't use `getFieldIndex` in these
places, we also should not.

All the remaining usages of `getFieldIndex` are ok.
lanza pushed a commit that referenced this pull request Jan 29, 2024
)

There is a bug in the code generation: the field index for the
`GetMemberOp` is taken from the `FieldDecl`, with no respect to the
record layout. One of the manifestation of the bug is the wrong index
generated for a field in a derived class that does not take into the
account the instance of the base class (that has index 0).

You can take a look at the example in
`test/CIR/CodeGen/derived-to-base.cpp`, i.e. the current test is not the
correct one
```
// CHECK-DAG: !ty_22C23A3ALayer22 = !cir.struct<class "C2::Layer" {!ty_22C13A3ALayer22, !cir.ptr<!ty_22C222>
// CHECK-DAG: !ty_22C33A3ALayer22 = !cir.struct<struct "C3::Layer" {!ty_22C23A3ALayer22

// CHECK: cir.func @_ZN2C35Layer10InitializeEv

// CHECK:  cir.scope {
// CHECK:    %2 = cir.base_class_addr(%1 : cir.ptr <!ty_22C33A3ALayer22>) -> cir.ptr <!ty_22C23A3ALayer22>
// CHECK:    %3 = cir.get_member %2[0] {name = "m_C1"} : !cir.ptr<!ty_22C23A3ALayer22> -> !cir.ptr<!cir.ptr<!ty_22C222>>
```
As one can see, the result (of ptr type to `!ty_22C222` ) must have the
index `1` in the corresponded struct `ty_22C23A3ALayer22`.

Basically the same is done in the `clang/CodeGen/CGExpr.cpp`, so we
don't invent something new here.

Note, this fix doesn't affect anything related to the usage of
`buildPreserveStructAccess` where the `field->getFieldIndex()` is used.
lanza pushed a commit that referenced this pull request Jan 29, 2024
#270)

This is a minor fix similar to the one introduced in #263.
Basically, all calls to the `buildLValueForFieldInitialization` are even
with the origin codegen `emitLValueForFieldInitialization` calls, i.e.
the field index is calculated from the record layout, but not from the
decl `field->getFieldIndex()`.

Added just one test, because looks like we need to implement some `NYI`
features first to test another places e.g. in `CIRGenExprAgg.cpp`,
though I could miss something.

Anyway, given the original codegen doesn't use `getFieldIndex` in these
places, we also should not.

All the remaining usages of `getFieldIndex` are ok.
lanza pushed a commit that referenced this pull request Mar 23, 2024
)

There is a bug in the code generation: the field index for the
`GetMemberOp` is taken from the `FieldDecl`, with no respect to the
record layout. One of the manifestation of the bug is the wrong index
generated for a field in a derived class that does not take into the
account the instance of the base class (that has index 0).

You can take a look at the example in
`test/CIR/CodeGen/derived-to-base.cpp`, i.e. the current test is not the
correct one
```
// CHECK-DAG: !ty_22C23A3ALayer22 = !cir.struct<class "C2::Layer" {!ty_22C13A3ALayer22, !cir.ptr<!ty_22C222>
// CHECK-DAG: !ty_22C33A3ALayer22 = !cir.struct<struct "C3::Layer" {!ty_22C23A3ALayer22

// CHECK: cir.func @_ZN2C35Layer10InitializeEv

// CHECK:  cir.scope {
// CHECK:    %2 = cir.base_class_addr(%1 : cir.ptr <!ty_22C33A3ALayer22>) -> cir.ptr <!ty_22C23A3ALayer22>
// CHECK:    %3 = cir.get_member %2[0] {name = "m_C1"} : !cir.ptr<!ty_22C23A3ALayer22> -> !cir.ptr<!cir.ptr<!ty_22C222>>
```
As one can see, the result (of ptr type to `!ty_22C222` ) must have the
index `1` in the corresponded struct `ty_22C23A3ALayer22`.

Basically the same is done in the `clang/CodeGen/CGExpr.cpp`, so we
don't invent something new here.

Note, this fix doesn't affect anything related to the usage of
`buildPreserveStructAccess` where the `field->getFieldIndex()` is used.
lanza pushed a commit that referenced this pull request Mar 23, 2024
#270)

This is a minor fix similar to the one introduced in #263.
Basically, all calls to the `buildLValueForFieldInitialization` are even
with the origin codegen `emitLValueForFieldInitialization` calls, i.e.
the field index is calculated from the record layout, but not from the
decl `field->getFieldIndex()`.

Added just one test, because looks like we need to implement some `NYI`
features first to test another places e.g. in `CIRGenExprAgg.cpp`,
though I could miss something.

Anyway, given the original codegen doesn't use `getFieldIndex` in these
places, we also should not.

All the remaining usages of `getFieldIndex` are ok.
eZWALT pushed a commit to eZWALT/clangir that referenced this pull request Mar 24, 2024
…lvm#263)

There is a bug in the code generation: the field index for the
`GetMemberOp` is taken from the `FieldDecl`, with no respect to the
record layout. One of the manifestation of the bug is the wrong index
generated for a field in a derived class that does not take into the
account the instance of the base class (that has index 0).

You can take a look at the example in
`test/CIR/CodeGen/derived-to-base.cpp`, i.e. the current test is not the
correct one
```
// CHECK-DAG: !ty_22C23A3ALayer22 = !cir.struct<class "C2::Layer" {!ty_22C13A3ALayer22, !cir.ptr<!ty_22C222>
// CHECK-DAG: !ty_22C33A3ALayer22 = !cir.struct<struct "C3::Layer" {!ty_22C23A3ALayer22

// CHECK: cir.func @_ZN2C35Layer10InitializeEv

// CHECK:  cir.scope {
// CHECK:    %2 = cir.base_class_addr(%1 : cir.ptr <!ty_22C33A3ALayer22>) -> cir.ptr <!ty_22C23A3ALayer22>
// CHECK:    %3 = cir.get_member %2[0] {name = "m_C1"} : !cir.ptr<!ty_22C23A3ALayer22> -> !cir.ptr<!cir.ptr<!ty_22C222>>
```
As one can see, the result (of ptr type to `!ty_22C222` ) must have the
index `1` in the corresponded struct `ty_22C23A3ALayer22`.

Basically the same is done in the `clang/CodeGen/CGExpr.cpp`, so we
don't invent something new here.

Note, this fix doesn't affect anything related to the usage of
`buildPreserveStructAccess` where the `field->getFieldIndex()` is used.
eZWALT pushed a commit to eZWALT/clangir that referenced this pull request Mar 24, 2024
llvm#270)

This is a minor fix similar to the one introduced in llvm#263.
Basically, all calls to the `buildLValueForFieldInitialization` are even
with the origin codegen `emitLValueForFieldInitialization` calls, i.e.
the field index is calculated from the record layout, but not from the
decl `field->getFieldIndex()`.

Added just one test, because looks like we need to implement some `NYI`
features first to test another places e.g. in `CIRGenExprAgg.cpp`,
though I could miss something.

Anyway, given the original codegen doesn't use `getFieldIndex` in these
places, we also should not.

All the remaining usages of `getFieldIndex` are ok.
eZWALT pushed a commit to eZWALT/clangir that referenced this pull request Mar 24, 2024
…lvm#263)

There is a bug in the code generation: the field index for the
`GetMemberOp` is taken from the `FieldDecl`, with no respect to the
record layout. One of the manifestation of the bug is the wrong index
generated for a field in a derived class that does not take into the
account the instance of the base class (that has index 0).

You can take a look at the example in
`test/CIR/CodeGen/derived-to-base.cpp`, i.e. the current test is not the
correct one
```
// CHECK-DAG: !ty_22C23A3ALayer22 = !cir.struct<class "C2::Layer" {!ty_22C13A3ALayer22, !cir.ptr<!ty_22C222>
// CHECK-DAG: !ty_22C33A3ALayer22 = !cir.struct<struct "C3::Layer" {!ty_22C23A3ALayer22

// CHECK: cir.func @_ZN2C35Layer10InitializeEv

// CHECK:  cir.scope {
// CHECK:    %2 = cir.base_class_addr(%1 : cir.ptr <!ty_22C33A3ALayer22>) -> cir.ptr <!ty_22C23A3ALayer22>
// CHECK:    %3 = cir.get_member %2[0] {name = "m_C1"} : !cir.ptr<!ty_22C23A3ALayer22> -> !cir.ptr<!cir.ptr<!ty_22C222>>
```
As one can see, the result (of ptr type to `!ty_22C222` ) must have the
index `1` in the corresponded struct `ty_22C23A3ALayer22`.

Basically the same is done in the `clang/CodeGen/CGExpr.cpp`, so we
don't invent something new here.

Note, this fix doesn't affect anything related to the usage of
`buildPreserveStructAccess` where the `field->getFieldIndex()` is used.
eZWALT pushed a commit to eZWALT/clangir that referenced this pull request Mar 24, 2024
llvm#270)

This is a minor fix similar to the one introduced in llvm#263.
Basically, all calls to the `buildLValueForFieldInitialization` are even
with the origin codegen `emitLValueForFieldInitialization` calls, i.e.
the field index is calculated from the record layout, but not from the
decl `field->getFieldIndex()`.

Added just one test, because looks like we need to implement some `NYI`
features first to test another places e.g. in `CIRGenExprAgg.cpp`,
though I could miss something.

Anyway, given the original codegen doesn't use `getFieldIndex` in these
places, we also should not.

All the remaining usages of `getFieldIndex` are ok.
lanza pushed a commit that referenced this pull request Apr 29, 2024
)

There is a bug in the code generation: the field index for the
`GetMemberOp` is taken from the `FieldDecl`, with no respect to the
record layout. One of the manifestation of the bug is the wrong index
generated for a field in a derived class that does not take into the
account the instance of the base class (that has index 0).

You can take a look at the example in
`test/CIR/CodeGen/derived-to-base.cpp`, i.e. the current test is not the
correct one
```
// CHECK-DAG: !ty_22C23A3ALayer22 = !cir.struct<class "C2::Layer" {!ty_22C13A3ALayer22, !cir.ptr<!ty_22C222>
// CHECK-DAG: !ty_22C33A3ALayer22 = !cir.struct<struct "C3::Layer" {!ty_22C23A3ALayer22

// CHECK: cir.func @_ZN2C35Layer10InitializeEv

// CHECK:  cir.scope {
// CHECK:    %2 = cir.base_class_addr(%1 : cir.ptr <!ty_22C33A3ALayer22>) -> cir.ptr <!ty_22C23A3ALayer22>
// CHECK:    %3 = cir.get_member %2[0] {name = "m_C1"} : !cir.ptr<!ty_22C23A3ALayer22> -> !cir.ptr<!cir.ptr<!ty_22C222>>
```
As one can see, the result (of ptr type to `!ty_22C222` ) must have the
index `1` in the corresponded struct `ty_22C23A3ALayer22`.

Basically the same is done in the `clang/CodeGen/CGExpr.cpp`, so we
don't invent something new here.

Note, this fix doesn't affect anything related to the usage of
`buildPreserveStructAccess` where the `field->getFieldIndex()` is used.
lanza pushed a commit that referenced this pull request Apr 29, 2024
#270)

This is a minor fix similar to the one introduced in #263.
Basically, all calls to the `buildLValueForFieldInitialization` are even
with the origin codegen `emitLValueForFieldInitialization` calls, i.e.
the field index is calculated from the record layout, but not from the
decl `field->getFieldIndex()`.

Added just one test, because looks like we need to implement some `NYI`
features first to test another places e.g. in `CIRGenExprAgg.cpp`,
though I could miss something.

Anyway, given the original codegen doesn't use `getFieldIndex` in these
places, we also should not.

All the remaining usages of `getFieldIndex` are ok.
lanza pushed a commit that referenced this pull request Apr 29, 2024
)

There is a bug in the code generation: the field index for the
`GetMemberOp` is taken from the `FieldDecl`, with no respect to the
record layout. One of the manifestation of the bug is the wrong index
generated for a field in a derived class that does not take into the
account the instance of the base class (that has index 0).

You can take a look at the example in
`test/CIR/CodeGen/derived-to-base.cpp`, i.e. the current test is not the
correct one
```
// CHECK-DAG: !ty_22C23A3ALayer22 = !cir.struct<class "C2::Layer" {!ty_22C13A3ALayer22, !cir.ptr<!ty_22C222>
// CHECK-DAG: !ty_22C33A3ALayer22 = !cir.struct<struct "C3::Layer" {!ty_22C23A3ALayer22

// CHECK: cir.func @_ZN2C35Layer10InitializeEv

// CHECK:  cir.scope {
// CHECK:    %2 = cir.base_class_addr(%1 : cir.ptr <!ty_22C33A3ALayer22>) -> cir.ptr <!ty_22C23A3ALayer22>
// CHECK:    %3 = cir.get_member %2[0] {name = "m_C1"} : !cir.ptr<!ty_22C23A3ALayer22> -> !cir.ptr<!cir.ptr<!ty_22C222>>
```
As one can see, the result (of ptr type to `!ty_22C222` ) must have the
index `1` in the corresponded struct `ty_22C23A3ALayer22`.

Basically the same is done in the `clang/CodeGen/CGExpr.cpp`, so we
don't invent something new here.

Note, this fix doesn't affect anything related to the usage of
`buildPreserveStructAccess` where the `field->getFieldIndex()` is used.
lanza pushed a commit that referenced this pull request Apr 29, 2024
#270)

This is a minor fix similar to the one introduced in #263.
Basically, all calls to the `buildLValueForFieldInitialization` are even
with the origin codegen `emitLValueForFieldInitialization` calls, i.e.
the field index is calculated from the record layout, but not from the
decl `field->getFieldIndex()`.

Added just one test, because looks like we need to implement some `NYI`
features first to test another places e.g. in `CIRGenExprAgg.cpp`,
though I could miss something.

Anyway, given the original codegen doesn't use `getFieldIndex` in these
places, we also should not.

All the remaining usages of `getFieldIndex` are ok.
eZWALT pushed a commit to eZWALT/clangir that referenced this pull request Apr 29, 2024
…lvm#263)

There is a bug in the code generation: the field index for the
`GetMemberOp` is taken from the `FieldDecl`, with no respect to the
record layout. One of the manifestation of the bug is the wrong index
generated for a field in a derived class that does not take into the
account the instance of the base class (that has index 0).

You can take a look at the example in
`test/CIR/CodeGen/derived-to-base.cpp`, i.e. the current test is not the
correct one
```
// CHECK-DAG: !ty_22C23A3ALayer22 = !cir.struct<class "C2::Layer" {!ty_22C13A3ALayer22, !cir.ptr<!ty_22C222>
// CHECK-DAG: !ty_22C33A3ALayer22 = !cir.struct<struct "C3::Layer" {!ty_22C23A3ALayer22

// CHECK: cir.func @_ZN2C35Layer10InitializeEv

// CHECK:  cir.scope {
// CHECK:    %2 = cir.base_class_addr(%1 : cir.ptr <!ty_22C33A3ALayer22>) -> cir.ptr <!ty_22C23A3ALayer22>
// CHECK:    %3 = cir.get_member %2[0] {name = "m_C1"} : !cir.ptr<!ty_22C23A3ALayer22> -> !cir.ptr<!cir.ptr<!ty_22C222>>
```
As one can see, the result (of ptr type to `!ty_22C222` ) must have the
index `1` in the corresponded struct `ty_22C23A3ALayer22`.

Basically the same is done in the `clang/CodeGen/CGExpr.cpp`, so we
don't invent something new here.

Note, this fix doesn't affect anything related to the usage of
`buildPreserveStructAccess` where the `field->getFieldIndex()` is used.
eZWALT pushed a commit to eZWALT/clangir that referenced this pull request Apr 29, 2024
llvm#270)

This is a minor fix similar to the one introduced in llvm#263.
Basically, all calls to the `buildLValueForFieldInitialization` are even
with the origin codegen `emitLValueForFieldInitialization` calls, i.e.
the field index is calculated from the record layout, but not from the
decl `field->getFieldIndex()`.

Added just one test, because looks like we need to implement some `NYI`
features first to test another places e.g. in `CIRGenExprAgg.cpp`,
though I could miss something.

Anyway, given the original codegen doesn't use `getFieldIndex` in these
places, we also should not.

All the remaining usages of `getFieldIndex` are ok.
lanza pushed a commit that referenced this pull request Apr 29, 2024
)

There is a bug in the code generation: the field index for the
`GetMemberOp` is taken from the `FieldDecl`, with no respect to the
record layout. One of the manifestation of the bug is the wrong index
generated for a field in a derived class that does not take into the
account the instance of the base class (that has index 0).

You can take a look at the example in
`test/CIR/CodeGen/derived-to-base.cpp`, i.e. the current test is not the
correct one
```
// CHECK-DAG: !ty_22C23A3ALayer22 = !cir.struct<class "C2::Layer" {!ty_22C13A3ALayer22, !cir.ptr<!ty_22C222>
// CHECK-DAG: !ty_22C33A3ALayer22 = !cir.struct<struct "C3::Layer" {!ty_22C23A3ALayer22

// CHECK: cir.func @_ZN2C35Layer10InitializeEv

// CHECK:  cir.scope {
// CHECK:    %2 = cir.base_class_addr(%1 : cir.ptr <!ty_22C33A3ALayer22>) -> cir.ptr <!ty_22C23A3ALayer22>
// CHECK:    %3 = cir.get_member %2[0] {name = "m_C1"} : !cir.ptr<!ty_22C23A3ALayer22> -> !cir.ptr<!cir.ptr<!ty_22C222>>
```
As one can see, the result (of ptr type to `!ty_22C222` ) must have the
index `1` in the corresponded struct `ty_22C23A3ALayer22`.

Basically the same is done in the `clang/CodeGen/CGExpr.cpp`, so we
don't invent something new here.

Note, this fix doesn't affect anything related to the usage of
`buildPreserveStructAccess` where the `field->getFieldIndex()` is used.
lanza pushed a commit that referenced this pull request Apr 29, 2024
#270)

This is a minor fix similar to the one introduced in #263.
Basically, all calls to the `buildLValueForFieldInitialization` are even
with the origin codegen `emitLValueForFieldInitialization` calls, i.e.
the field index is calculated from the record layout, but not from the
decl `field->getFieldIndex()`.

Added just one test, because looks like we need to implement some `NYI`
features first to test another places e.g. in `CIRGenExprAgg.cpp`,
though I could miss something.

Anyway, given the original codegen doesn't use `getFieldIndex` in these
places, we also should not.

All the remaining usages of `getFieldIndex` are ok.
bruteforceboy pushed a commit to bruteforceboy/clangir that referenced this pull request Oct 2, 2024
…lvm#263)

There is a bug in the code generation: the field index for the
`GetMemberOp` is taken from the `FieldDecl`, with no respect to the
record layout. One of the manifestation of the bug is the wrong index
generated for a field in a derived class that does not take into the
account the instance of the base class (that has index 0).

You can take a look at the example in
`test/CIR/CodeGen/derived-to-base.cpp`, i.e. the current test is not the
correct one
```
// CHECK-DAG: !ty_22C23A3ALayer22 = !cir.struct<class "C2::Layer" {!ty_22C13A3ALayer22, !cir.ptr<!ty_22C222>
// CHECK-DAG: !ty_22C33A3ALayer22 = !cir.struct<struct "C3::Layer" {!ty_22C23A3ALayer22

// CHECK: cir.func @_ZN2C35Layer10InitializeEv

// CHECK:  cir.scope {
// CHECK:    %2 = cir.base_class_addr(%1 : cir.ptr <!ty_22C33A3ALayer22>) -> cir.ptr <!ty_22C23A3ALayer22>
// CHECK:    %3 = cir.get_member %2[0] {name = "m_C1"} : !cir.ptr<!ty_22C23A3ALayer22> -> !cir.ptr<!cir.ptr<!ty_22C222>>
```
As one can see, the result (of ptr type to `!ty_22C222` ) must have the
index `1` in the corresponded struct `ty_22C23A3ALayer22`.

Basically the same is done in the `clang/CodeGen/CGExpr.cpp`, so we
don't invent something new here.

Note, this fix doesn't affect anything related to the usage of
`buildPreserveStructAccess` where the `field->getFieldIndex()` is used.
bruteforceboy pushed a commit to bruteforceboy/clangir that referenced this pull request Oct 2, 2024
llvm#270)

This is a minor fix similar to the one introduced in llvm#263.
Basically, all calls to the `buildLValueForFieldInitialization` are even
with the origin codegen `emitLValueForFieldInitialization` calls, i.e.
the field index is calculated from the record layout, but not from the
decl `field->getFieldIndex()`.

Added just one test, because looks like we need to implement some `NYI`
features first to test another places e.g. in `CIRGenExprAgg.cpp`,
though I could miss something.

Anyway, given the original codegen doesn't use `getFieldIndex` in these
places, we also should not.

All the remaining usages of `getFieldIndex` are ok.
Hugobros3 pushed a commit to shady-gang/clangir that referenced this pull request Oct 2, 2024
…lvm#263)

There is a bug in the code generation: the field index for the
`GetMemberOp` is taken from the `FieldDecl`, with no respect to the
record layout. One of the manifestation of the bug is the wrong index
generated for a field in a derived class that does not take into the
account the instance of the base class (that has index 0).

You can take a look at the example in
`test/CIR/CodeGen/derived-to-base.cpp`, i.e. the current test is not the
correct one
```
// CHECK-DAG: !ty_22C23A3ALayer22 = !cir.struct<class "C2::Layer" {!ty_22C13A3ALayer22, !cir.ptr<!ty_22C222>
// CHECK-DAG: !ty_22C33A3ALayer22 = !cir.struct<struct "C3::Layer" {!ty_22C23A3ALayer22

// CHECK: cir.func @_ZN2C35Layer10InitializeEv

// CHECK:  cir.scope {
// CHECK:    %2 = cir.base_class_addr(%1 : cir.ptr <!ty_22C33A3ALayer22>) -> cir.ptr <!ty_22C23A3ALayer22>
// CHECK:    %3 = cir.get_member %2[0] {name = "m_C1"} : !cir.ptr<!ty_22C23A3ALayer22> -> !cir.ptr<!cir.ptr<!ty_22C222>>
```
As one can see, the result (of ptr type to `!ty_22C222` ) must have the
index `1` in the corresponded struct `ty_22C23A3ALayer22`.

Basically the same is done in the `clang/CodeGen/CGExpr.cpp`, so we
don't invent something new here.

Note, this fix doesn't affect anything related to the usage of
`buildPreserveStructAccess` where the `field->getFieldIndex()` is used.
Hugobros3 pushed a commit to shady-gang/clangir that referenced this pull request Oct 2, 2024
llvm#270)

This is a minor fix similar to the one introduced in llvm#263.
Basically, all calls to the `buildLValueForFieldInitialization` are even
with the origin codegen `emitLValueForFieldInitialization` calls, i.e.
the field index is calculated from the record layout, but not from the
decl `field->getFieldIndex()`.

Added just one test, because looks like we need to implement some `NYI`
features first to test another places e.g. in `CIRGenExprAgg.cpp`,
though I could miss something.

Anyway, given the original codegen doesn't use `getFieldIndex` in these
places, we also should not.

All the remaining usages of `getFieldIndex` are ok.
keryell pushed a commit to keryell/clangir that referenced this pull request Oct 19, 2024
…lvm#263)

There is a bug in the code generation: the field index for the
`GetMemberOp` is taken from the `FieldDecl`, with no respect to the
record layout. One of the manifestation of the bug is the wrong index
generated for a field in a derived class that does not take into the
account the instance of the base class (that has index 0).

You can take a look at the example in
`test/CIR/CodeGen/derived-to-base.cpp`, i.e. the current test is not the
correct one
```
// CHECK-DAG: !ty_22C23A3ALayer22 = !cir.struct<class "C2::Layer" {!ty_22C13A3ALayer22, !cir.ptr<!ty_22C222>
// CHECK-DAG: !ty_22C33A3ALayer22 = !cir.struct<struct "C3::Layer" {!ty_22C23A3ALayer22

// CHECK: cir.func @_ZN2C35Layer10InitializeEv

// CHECK:  cir.scope {
// CHECK:    %2 = cir.base_class_addr(%1 : cir.ptr <!ty_22C33A3ALayer22>) -> cir.ptr <!ty_22C23A3ALayer22>
// CHECK:    %3 = cir.get_member %2[0] {name = "m_C1"} : !cir.ptr<!ty_22C23A3ALayer22> -> !cir.ptr<!cir.ptr<!ty_22C222>>
```
As one can see, the result (of ptr type to `!ty_22C222` ) must have the
index `1` in the corresponded struct `ty_22C23A3ALayer22`.

Basically the same is done in the `clang/CodeGen/CGExpr.cpp`, so we
don't invent something new here.

Note, this fix doesn't affect anything related to the usage of
`buildPreserveStructAccess` where the `field->getFieldIndex()` is used.
keryell pushed a commit to keryell/clangir that referenced this pull request Oct 19, 2024
llvm#270)

This is a minor fix similar to the one introduced in llvm#263.
Basically, all calls to the `buildLValueForFieldInitialization` are even
with the origin codegen `emitLValueForFieldInitialization` calls, i.e.
the field index is calculated from the record layout, but not from the
decl `field->getFieldIndex()`.

Added just one test, because looks like we need to implement some `NYI`
features first to test another places e.g. in `CIRGenExprAgg.cpp`,
though I could miss something.

Anyway, given the original codegen doesn't use `getFieldIndex` in these
places, we also should not.

All the remaining usages of `getFieldIndex` are ok.
lanza pushed a commit that referenced this pull request Nov 5, 2024
)

There is a bug in the code generation: the field index for the
`GetMemberOp` is taken from the `FieldDecl`, with no respect to the
record layout. One of the manifestation of the bug is the wrong index
generated for a field in a derived class that does not take into the
account the instance of the base class (that has index 0).

You can take a look at the example in
`test/CIR/CodeGen/derived-to-base.cpp`, i.e. the current test is not the
correct one
```
// CHECK-DAG: !ty_22C23A3ALayer22 = !cir.struct<class "C2::Layer" {!ty_22C13A3ALayer22, !cir.ptr<!ty_22C222>
// CHECK-DAG: !ty_22C33A3ALayer22 = !cir.struct<struct "C3::Layer" {!ty_22C23A3ALayer22

// CHECK: cir.func @_ZN2C35Layer10InitializeEv

// CHECK:  cir.scope {
// CHECK:    %2 = cir.base_class_addr(%1 : cir.ptr <!ty_22C33A3ALayer22>) -> cir.ptr <!ty_22C23A3ALayer22>
// CHECK:    %3 = cir.get_member %2[0] {name = "m_C1"} : !cir.ptr<!ty_22C23A3ALayer22> -> !cir.ptr<!cir.ptr<!ty_22C222>>
```
As one can see, the result (of ptr type to `!ty_22C222` ) must have the
index `1` in the corresponded struct `ty_22C23A3ALayer22`.

Basically the same is done in the `clang/CodeGen/CGExpr.cpp`, so we
don't invent something new here.

Note, this fix doesn't affect anything related to the usage of
`buildPreserveStructAccess` where the `field->getFieldIndex()` is used.
lanza pushed a commit that referenced this pull request Nov 5, 2024
#270)

This is a minor fix similar to the one introduced in #263.
Basically, all calls to the `buildLValueForFieldInitialization` are even
with the origin codegen `emitLValueForFieldInitialization` calls, i.e.
the field index is calculated from the record layout, but not from the
decl `field->getFieldIndex()`.

Added just one test, because looks like we need to implement some `NYI`
features first to test another places e.g. in `CIRGenExprAgg.cpp`,
though I could miss something.

Anyway, given the original codegen doesn't use `getFieldIndex` in these
places, we also should not.

All the remaining usages of `getFieldIndex` are ok.
lanza pushed a commit that referenced this pull request Mar 18, 2025
)

There is a bug in the code generation: the field index for the
`GetMemberOp` is taken from the `FieldDecl`, with no respect to the
record layout. One of the manifestation of the bug is the wrong index
generated for a field in a derived class that does not take into the
account the instance of the base class (that has index 0).

You can take a look at the example in
`test/CIR/CodeGen/derived-to-base.cpp`, i.e. the current test is not the
correct one
```
// CHECK-DAG: !ty_22C23A3ALayer22 = !cir.struct<class "C2::Layer" {!ty_22C13A3ALayer22, !cir.ptr<!ty_22C222>
// CHECK-DAG: !ty_22C33A3ALayer22 = !cir.struct<struct "C3::Layer" {!ty_22C23A3ALayer22

// CHECK: cir.func @_ZN2C35Layer10InitializeEv

// CHECK:  cir.scope {
// CHECK:    %2 = cir.base_class_addr(%1 : cir.ptr <!ty_22C33A3ALayer22>) -> cir.ptr <!ty_22C23A3ALayer22>
// CHECK:    %3 = cir.get_member %2[0] {name = "m_C1"} : !cir.ptr<!ty_22C23A3ALayer22> -> !cir.ptr<!cir.ptr<!ty_22C222>>
```
As one can see, the result (of ptr type to `!ty_22C222` ) must have the
index `1` in the corresponded struct `ty_22C23A3ALayer22`.

Basically the same is done in the `clang/CodeGen/CGExpr.cpp`, so we
don't invent something new here.

Note, this fix doesn't affect anything related to the usage of
`buildPreserveStructAccess` where the `field->getFieldIndex()` is used.
lanza pushed a commit that referenced this pull request Mar 18, 2025
#270)

This is a minor fix similar to the one introduced in #263.
Basically, all calls to the `buildLValueForFieldInitialization` are even
with the origin codegen `emitLValueForFieldInitialization` calls, i.e.
the field index is calculated from the record layout, but not from the
decl `field->getFieldIndex()`.

Added just one test, because looks like we need to implement some `NYI`
features first to test another places e.g. in `CIRGenExprAgg.cpp`,
though I could miss something.

Anyway, given the original codegen doesn't use `getFieldIndex` in these
places, we also should not.

All the remaining usages of `getFieldIndex` are ok.
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