Skip to content

Commit c7d518a

Browse files
committed
Fix ClassMetadataBuilderBase::FieldLayout ASAN violations
There’s something Off™ about the ClassMetadataBuilderBase<Derived>::FieldLayout reference inherited by SpecializedGenericClassMetadataBuilder; work around it by using an accessor that accesses a derived-class equivalent. Fixes widespread test failures in unoptimized swift-frontends.
1 parent 4d2739a commit c7d518a

File tree

2 files changed

+20
-17
lines changed

2 files changed

+20
-17
lines changed

lib/IRGen/GenMeta.cpp

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3440,6 +3440,8 @@ namespace {
34403440
MetadataLayout(IGM.getClassMetadataLayout(theClass)) {}
34413441

34423442
public:
3443+
const ClassLayout &getFieldLayout() const { return FieldLayout; }
3444+
34433445
SILType getLoweredType() {
34443446
return IGM.getLoweredType(Target->getDeclaredTypeInContext());
34453447
}
@@ -3452,7 +3454,7 @@ namespace {
34523454
ClassFlags getClassFlags() { return ::getClassFlags(Target); }
34533455

34543456
void addClassFlags() {
3455-
if (FieldLayout.hasObjCImplementation())
3457+
if (asImpl().getFieldLayout().hasObjCImplementation())
34563458
return;
34573459

34583460
B.addInt32((uint32_t)asImpl().getClassFlags());
@@ -3490,7 +3492,7 @@ namespace {
34903492
}
34913493

34923494
void addValueWitnessTable() {
3493-
if (FieldLayout.hasObjCImplementation())
3495+
if (asImpl().getFieldLayout().hasObjCImplementation())
34943496
return;
34953497

34963498
B.add(asImpl().getValueWitnessTable(false).getValue());
@@ -3583,7 +3585,7 @@ namespace {
35833585
}
35843586

35853587
void addDestructorFunction() {
3586-
if (FieldLayout.hasObjCImplementation())
3588+
if (asImpl().getFieldLayout().hasObjCImplementation())
35873589
return;
35883590

35893591
if (auto ptr = getAddrOfDestructorFunction(IGM, Target)) {
@@ -3598,7 +3600,7 @@ namespace {
35983600
}
35993601

36003602
void addIVarDestroyer() {
3601-
if (FieldLayout.hasObjCImplementation())
3603+
if (asImpl().getFieldLayout().hasObjCImplementation())
36023604
return;
36033605

36043606
auto dtorFunc = IGM.getAddrOfIVarInitDestroy(Target,
@@ -3623,7 +3625,7 @@ namespace {
36233625
}
36243626

36253627
void addNominalTypeDescriptor() {
3626-
if (FieldLayout.hasObjCImplementation())
3628+
if (asImpl().getFieldLayout().hasObjCImplementation())
36273629
return;
36283630

36293631
B.addSignedPointer(asImpl().getNominalTypeDescriptor(),
@@ -3640,7 +3642,7 @@ namespace {
36403642
}
36413643

36423644
void addInstanceAddressPoint() {
3643-
if (FieldLayout.hasObjCImplementation())
3645+
if (asImpl().getFieldLayout().hasObjCImplementation())
36443646
return;
36453647

36463648
// Right now, we never allocate fields before the address point.
@@ -3652,7 +3654,7 @@ namespace {
36523654
const ClassLayout &getFieldLayout() { return FieldLayout; }
36533655

36543656
void addInstanceSize() {
3655-
if (FieldLayout.hasObjCImplementation())
3657+
if (asImpl().getFieldLayout().hasObjCImplementation())
36563658
return;
36573659

36583660
if (asImpl().hasFixedLayout()) {
@@ -3664,7 +3666,7 @@ namespace {
36643666
}
36653667

36663668
void addInstanceAlignMask() {
3667-
if (FieldLayout.hasObjCImplementation())
3669+
if (asImpl().getFieldLayout().hasObjCImplementation())
36683670
return;
36693671

36703672
if (asImpl().hasFixedLayout()) {
@@ -3676,22 +3678,22 @@ namespace {
36763678
}
36773679

36783680
void addRuntimeReservedBits() {
3679-
if (FieldLayout.hasObjCImplementation())
3681+
if (asImpl().getFieldLayout().hasObjCImplementation())
36803682
return;
36813683

36823684
B.addInt16(0);
36833685
}
36843686

36853687
void addClassSize() {
3686-
if (FieldLayout.hasObjCImplementation())
3688+
if (asImpl().getFieldLayout().hasObjCImplementation())
36873689
return;
36883690

36893691
auto size = MetadataLayout.getSize();
36903692
B.addInt32(size.FullSize.getValue());
36913693
}
36923694

36933695
void addClassAddressPoint() {
3694-
if (FieldLayout.hasObjCImplementation())
3696+
if (asImpl().getFieldLayout().hasObjCImplementation())
36953697
return;
36963698

36973699
// FIXME: Wrong
@@ -3725,7 +3727,7 @@ namespace {
37253727
// Derive the RO-data.
37263728
llvm::Constant *data = asImpl().getROData();
37273729

3728-
if (!FieldLayout.hasObjCImplementation()) {
3730+
if (!asImpl().getFieldLayout().hasObjCImplementation()) {
37293731
// Set a low bit to indicate this class has Swift metadata.
37303732
auto bit = llvm::ConstantInt::get(
37313733
IGM.IntPtrTy, asImpl().getClassDataPointerHasSwiftMetadataBits());
@@ -3833,7 +3835,7 @@ namespace {
38333835
: super(IGM, theClass, builder, fieldLayout) {}
38343836

38353837
void addFieldOffset(VarDecl *var) {
3836-
if (FieldLayout.hasObjCImplementation())
3838+
if (asImpl().getFieldLayout().hasObjCImplementation())
38373839
return;
38383840

38393841
addFixedFieldOffset(IGM, B, var, [](DeclContext *dc) {
@@ -3872,7 +3874,7 @@ namespace {
38723874
: super(IGM, theClass, builder, fieldLayout) {}
38733875

38743876
void addFieldOffset(VarDecl *var) {
3875-
if (FieldLayout.hasObjCImplementation())
3877+
if (asImpl().getFieldLayout().hasObjCImplementation())
38763878
return;
38773879

38783880
// Field offsets are either copied from the superclass or calculated
@@ -3881,7 +3883,7 @@ namespace {
38813883
}
38823884

38833885
void addFieldOffsetPlaceholders(MissingMemberDecl *placeholder) {
3884-
if (FieldLayout.hasObjCImplementation())
3886+
if (asImpl().getFieldLayout().hasObjCImplementation())
38853887
return;
38863888

38873889
for (unsigned i = 0,
@@ -4343,7 +4345,7 @@ namespace {
43434345
}
43444346

43454347
void addFieldOffset(VarDecl *var) {
4346-
if (FieldLayout.hasObjCImplementation())
4348+
if (asImpl().getFieldLayout().hasObjCImplementation())
43474349
return;
43484350

43494351
addFixedFieldOffset(IGM, B, var, [&](DeclContext *dc) {

test/IRGen/prespecialized-metadata/class-fileprivate-inmodule-1argument-2ancestor-1du-1st_ancestor_generic-fileprivate-2nd_ancestor_nongeneric.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// RUN: %empty-directory(%t)
22

3-
// RUN: %target-swift-frontend -prespecialize-generic-metadata -target %module-target-future -emit-ir -I %t -L %t %s | %FileCheck %s -DINT=i%target-ptrsize -DALIGNMENT=%target-alignment --check-prefix=CHECK --check-prefix=CHECK-%target-vendor
3+
// RUN: %target-swift-frontend -prespecialize-generic-metadata -target %module-target-future -emit-ir -I %t -L %t %s > %t/out.ir
4+
// RUN: %FileCheck --input-file=%t/out.ir %s -DINT=i%target-ptrsize -DALIGNMENT=%target-alignment --check-prefix=CHECK --check-prefix=CHECK-%target-vendor
45

56
// REQUIRES: VENDOR=apple || OS=linux-gnu
67
// UNSUPPORTED: CPU=i386 && OS=ios

0 commit comments

Comments
 (0)