[AST] Do not align virtual bases in `MicrosoftRecordLayoutBuilder` when
an external layout is used
Summary:
The patch removes alignment of virtual bases when an external layout is used.
We have two cases:
- the external layout source has an information about virtual bases offsets,
so we just use them;
- the external source has no information about virtual bases offsets. In this
case we can't predict where the base will be located. If we will align it but
there will be something like `#pragma pack(push, 1)` really, then likely our
layout will not fit into the real structure size, and then some asserts will
hit. The asserts look reasonable, so I don't think that we need to remove
them. May be it would be better instead don't align fields / bases etc.
(so treat it always as `#pragma pack(push, 1)`) when an external layout source
is used but no info about a field location is presented.
This one is related to D49871
Reviewers: rnk, rsmith, zturner, mstorsjo, majnemer
Reviewed By: rnk
Subscribers: cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D53497
llvm-svn: 345012
2018-10-23 16:23:22 +08:00
|
|
|
// RUN: %clang_cc1 -triple i686-windows-msvc -w -fdump-record-layouts-simple -foverride-record-layout=%S/Inputs/override-layout-packed-base.layout %s | FileCheck %s
|
|
|
|
|
|
|
|
//#pragma pack(push, 1)
|
2018-07-31 16:27:06 +08:00
|
|
|
|
|
|
|
// CHECK: Type: class B<0>
|
[AST] Do not align virtual bases in `MicrosoftRecordLayoutBuilder` when
an external layout is used
Summary:
The patch removes alignment of virtual bases when an external layout is used.
We have two cases:
- the external layout source has an information about virtual bases offsets,
so we just use them;
- the external source has no information about virtual bases offsets. In this
case we can't predict where the base will be located. If we will align it but
there will be something like `#pragma pack(push, 1)` really, then likely our
layout will not fit into the real structure size, and then some asserts will
hit. The asserts look reasonable, so I don't think that we need to remove
them. May be it would be better instead don't align fields / bases etc.
(so treat it always as `#pragma pack(push, 1)`) when an external layout source
is used but no info about a field location is presented.
This one is related to D49871
Reviewers: rnk, rsmith, zturner, mstorsjo, majnemer
Reviewed By: rnk
Subscribers: cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D53497
llvm-svn: 345012
2018-10-23 16:23:22 +08:00
|
|
|
// CHECK: Size:40
|
2018-07-31 16:27:06 +08:00
|
|
|
// CHECK: FieldOffsets: [0, 32]
|
|
|
|
|
|
|
|
// CHECK: Type: class B<1>
|
[AST] Do not align virtual bases in `MicrosoftRecordLayoutBuilder` when
an external layout is used
Summary:
The patch removes alignment of virtual bases when an external layout is used.
We have two cases:
- the external layout source has an information about virtual bases offsets,
so we just use them;
- the external source has no information about virtual bases offsets. In this
case we can't predict where the base will be located. If we will align it but
there will be something like `#pragma pack(push, 1)` really, then likely our
layout will not fit into the real structure size, and then some asserts will
hit. The asserts look reasonable, so I don't think that we need to remove
them. May be it would be better instead don't align fields / bases etc.
(so treat it always as `#pragma pack(push, 1)`) when an external layout source
is used but no info about a field location is presented.
This one is related to D49871
Reviewers: rnk, rsmith, zturner, mstorsjo, majnemer
Reviewed By: rnk
Subscribers: cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D53497
llvm-svn: 345012
2018-10-23 16:23:22 +08:00
|
|
|
// CHECK: Size:40
|
2018-07-31 16:27:06 +08:00
|
|
|
// CHECK: FieldOffsets: [0, 32]
|
|
|
|
|
|
|
|
template<int I>
|
|
|
|
class B {
|
|
|
|
int _b1;
|
|
|
|
char _b2;
|
|
|
|
};
|
|
|
|
|
|
|
|
// CHECK: Type: class C
|
[AST] Do not align virtual bases in `MicrosoftRecordLayoutBuilder` when
an external layout is used
Summary:
The patch removes alignment of virtual bases when an external layout is used.
We have two cases:
- the external layout source has an information about virtual bases offsets,
so we just use them;
- the external source has no information about virtual bases offsets. In this
case we can't predict where the base will be located. If we will align it but
there will be something like `#pragma pack(push, 1)` really, then likely our
layout will not fit into the real structure size, and then some asserts will
hit. The asserts look reasonable, so I don't think that we need to remove
them. May be it would be better instead don't align fields / bases etc.
(so treat it always as `#pragma pack(push, 1)`) when an external layout source
is used but no info about a field location is presented.
This one is related to D49871
Reviewers: rnk, rsmith, zturner, mstorsjo, majnemer
Reviewed By: rnk
Subscribers: cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D53497
llvm-svn: 345012
2018-10-23 16:23:22 +08:00
|
|
|
// CHECK: Size:88
|
2018-07-31 16:27:06 +08:00
|
|
|
// CHECK: FieldOffsets: [80]
|
|
|
|
|
|
|
|
class C : B<0>, B<1> {
|
|
|
|
char _c;
|
|
|
|
};
|
|
|
|
|
[AST] Do not align virtual bases in `MicrosoftRecordLayoutBuilder` when
an external layout is used
Summary:
The patch removes alignment of virtual bases when an external layout is used.
We have two cases:
- the external layout source has an information about virtual bases offsets,
so we just use them;
- the external source has no information about virtual bases offsets. In this
case we can't predict where the base will be located. If we will align it but
there will be something like `#pragma pack(push, 1)` really, then likely our
layout will not fit into the real structure size, and then some asserts will
hit. The asserts look reasonable, so I don't think that we need to remove
them. May be it would be better instead don't align fields / bases etc.
(so treat it always as `#pragma pack(push, 1)`) when an external layout source
is used but no info about a field location is presented.
This one is related to D49871
Reviewers: rnk, rsmith, zturner, mstorsjo, majnemer
Reviewed By: rnk
Subscribers: cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D53497
llvm-svn: 345012
2018-10-23 16:23:22 +08:00
|
|
|
// CHECK: Type: class D
|
|
|
|
// CHECK: Size:120
|
|
|
|
// CHECK: FieldOffsets: [32]
|
|
|
|
|
|
|
|
class D : virtual B<0>, virtual B<1> {
|
|
|
|
char _d;
|
|
|
|
};
|
|
|
|
|
|
|
|
//#pragma pack(pop)
|
|
|
|
|
2018-07-31 16:27:06 +08:00
|
|
|
void use_structs() {
|
|
|
|
C cs[sizeof(C)];
|
[AST] Do not align virtual bases in `MicrosoftRecordLayoutBuilder` when
an external layout is used
Summary:
The patch removes alignment of virtual bases when an external layout is used.
We have two cases:
- the external layout source has an information about virtual bases offsets,
so we just use them;
- the external source has no information about virtual bases offsets. In this
case we can't predict where the base will be located. If we will align it but
there will be something like `#pragma pack(push, 1)` really, then likely our
layout will not fit into the real structure size, and then some asserts will
hit. The asserts look reasonable, so I don't think that we need to remove
them. May be it would be better instead don't align fields / bases etc.
(so treat it always as `#pragma pack(push, 1)`) when an external layout source
is used but no info about a field location is presented.
This one is related to D49871
Reviewers: rnk, rsmith, zturner, mstorsjo, majnemer
Reviewed By: rnk
Subscribers: cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D53497
llvm-svn: 345012
2018-10-23 16:23:22 +08:00
|
|
|
D ds[sizeof(D)];
|
2018-07-31 16:27:06 +08:00
|
|
|
}
|