Skip to content

Commit 95e0a79

Browse files
authored
Merge pull request #77060 from drexin/wip-138074648
[IRGen] Properly handle ObjC class existentials in CVW generation
2 parents 687a7ef + 659b290 commit 95e0a79

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-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: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
// REQUIRES: objc_interop
5+
6+
protocol P {}
7+
8+
extension ObjCBase: P {}
9+
10+
// CHECK: @"type_layout_string 41layout_string_witnesses_objc_existentials27MultiPayloadObjCExistentialO" =
11+
// CHECK: internal constant <{ i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64 }>
12+
// 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),
13+
// CHECK: i64 ptrtoint (ptr getelementptr inbounds (<{ i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64 }>,
14+
// CHECK: ptr @"type_layout_string 41layout_string_witnesses_objc_existentials27MultiPayloadObjCExistentialO", i32 0, i32 3) to i64)),
15+
// CHECK: i64 2, i64 32, i64 16, i64 0, i64 16, i64 360287970189639680, i64 0, i64 720575940379279360, i64 0, i64 0 }>
16+
enum MultiPayloadObjCExistential {
17+
case x(AnyObject)
18+
case y(P & ObjCBase)
19+
}
20+
21+
// CHECK: @"type_layout_string 41layout_string_witnesses_objc_existentials34MultiPayloadObjCExistentialWrapperV" =
22+
// CHECK: internal constant <{ i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64 }>
23+
// 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),
24+
// CHECK: i64 ptrtoint (ptr getelementptr inbounds (<{ i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64 }>,
25+
// CHECK: ptr @"type_layout_string 41layout_string_witnesses_objc_existentials34MultiPayloadObjCExistentialWrapperV", i32 0, i32 3) to i64)),
26+
// CHECK: i64 2, i64 32, i64 16, i64 0, i64 16, i64 360287970189639680, i64 0, i64 720575940379279360, i64 0, i64 8 }>
27+
struct MultiPayloadObjCExistentialWrapper {
28+
let x: MultiPayloadObjCExistential
29+
let y: Int = 0
30+
}

0 commit comments

Comments
 (0)