Skip to content

Commit 35beae1

Browse files
committed
[IRGen] Properly handle ObjC class existentials in CVW generation
rdar://13807464 For most TypeInfo based layouts, we don't have enough information to emit CVW, but for ObjC class existentials it's trivial.
1 parent decab5d commit 35beae1

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

lib/IRGen/TypeLayout.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "IRGen.h"
2121
#include "IRGenFunction.h"
2222
#include "IRGenModule.h"
23+
#include "ReferenceTypeInfo.h"
2324
#include "SwitchBuilder.h"
2425
#include "swift/ABI/MetadataValues.h"
2526
#include "swift/AST/GenericEnvironment.h"
@@ -3830,6 +3831,13 @@ TypeInfoBasedTypeLayoutEntry::layoutString(IRGenModule &IGM,
38303831
bool TypeInfoBasedTypeLayoutEntry::refCountString(
38313832
IRGenModule &IGM, LayoutStringBuilder &B,
38323833
GenericSignature genericSig) const {
3834+
if (auto *refTI = dyn_cast<ReferenceTypeInfo>(&typeInfo)) {
3835+
if (refTI->getReferenceCountingType() == ReferenceCounting::ObjC) {
3836+
B.addRefCount(LayoutStringBuilder::RefCountingKind::ObjC,
3837+
typeInfo.getFixedSize().getValue());
3838+
return true;
3839+
}
3840+
}
38333841
return false;
38343842
}
38353843

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -enable-experimental-feature LayoutStringValueWitnesses -enable-experimental-feature LayoutStringValueWitnessesInstantiation -enable-layout-string-value-witnesses -enable-layout-string-value-witnesses-instantiation -emit-ir -import-objc-header %S/Inputs/ObjCBaseClasses.h %s | %FileCheck %s
2+
3+
// REQUIRES: PTRSIZE=64
4+
5+
protocol P {}
6+
7+
extension ObjCBase: P {}
8+
9+
// CHECK: @"type_layout_string 41layout_string_witnesses_objc_existentials27MultiPayloadObjCExistentialO" =
10+
// CHECK: internal constant <{ i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64 }>
11+
// CHECK: <{ i64 -9223372036854775808, i64 88, i64 1441151880758558720, i64 sub (i64 ptrtoint (ptr @"get_enum_tag_for_layout_string 41layout_string_witnesses_objc_existentials27MultiPayloadObjCExistentialO" to i64),
12+
// CHECK: i64 ptrtoint (ptr getelementptr inbounds (<{ i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64 }>,
13+
// CHECK: ptr @"type_layout_string 41layout_string_witnesses_objc_existentials27MultiPayloadObjCExistentialO", i32 0, i32 3) to i64)),
14+
// CHECK: i64 2, i64 32, i64 16, i64 0, i64 16, i64 360287970189639680, i64 0, i64 720575940379279360, i64 0, i64 0 }>
15+
enum MultiPayloadObjCExistential {
16+
case x(AnyObject)
17+
case y(P & ObjCBase)
18+
}
19+
20+
// CHECK: @"type_layout_string 41layout_string_witnesses_objc_existentials34MultiPayloadObjCExistentialWrapperV" =
21+
// CHECK: internal constant <{ i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64 }>
22+
// CHECK: <{ i64 -9223372036854775808, i64 88, i64 1441151880758558720, i64 sub (i64 ptrtoint (ptr @"get_enum_tag_for_layout_string 41layout_string_witnesses_objc_existentials27MultiPayloadObjCExistentialO" to i64),
23+
// CHECK: i64 ptrtoint (ptr getelementptr inbounds (<{ i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64 }>,
24+
// CHECK: ptr @"type_layout_string 41layout_string_witnesses_objc_existentials34MultiPayloadObjCExistentialWrapperV", i32 0, i32 3) to i64)),
25+
// CHECK: i64 2, i64 32, i64 16, i64 0, i64 16, i64 360287970189639680, i64 0, i64 720575940379279360, i64 0, i64 8 }>
26+
struct MultiPayloadObjCExistentialWrapper {
27+
let x: MultiPayloadObjCExistential
28+
let y: Int = 0
29+
}

0 commit comments

Comments
 (0)