Skip to content

Commit 4abed13

Browse files
committed
[IRGen] Do not use ObjC tagged-pointer logic on non-ObjC platforms
Please note that some ObjC tests moved out of test/IRGen/enum.sil and into test/IRGen/enum_objc.sil because `#if` does not work with SIL keywords.
1 parent 4ddeba1 commit 4abed13

File tree

6 files changed

+46
-19
lines changed

6 files changed

+46
-19
lines changed

include/swift/Runtime/Metadata.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4266,9 +4266,10 @@ inline int swift_getHeapObjectExtraInhabitantIndex(HeapObject * const* src) {
42664266
#if SWIFT_OBJC_INTEROP
42674267
if (value & ((uintptr_t(1) << ObjCReservedLowBits) - 1))
42684268
return -1;
4269+
return int(value >> ObjCReservedLowBits);
4270+
#else
4271+
return int(value);
42694272
#endif
4270-
4271-
return (int) (value >> ObjCReservedLowBits);
42724273
}
42734274

42744275
/// Store an extra inhabitant of a heap object pointer to memory,
@@ -4277,7 +4278,11 @@ inline void swift_storeHeapObjectExtraInhabitant(HeapObject **dest, int index) {
42774278
// This must be consistent with the storeHeapObjectExtraInhabitant
42784279
// implementation in IRGen's ExtraInhabitants.cpp.
42794280

4281+
#if SWIFT_OBJC_INTEROP
42804282
auto value = uintptr_t(index) << heap_object_abi::ObjCReservedLowBits;
4283+
#else
4284+
auto value = uintptr_t(index);
4285+
#endif
42814286
*dest = reinterpret_cast<HeapObject*>(value);
42824287
}
42834288

@@ -4289,9 +4294,15 @@ inline constexpr unsigned swift_getHeapObjectExtraInhabitantCount() {
42894294
using namespace heap_object_abi;
42904295

42914296
// The runtime needs no more than INT_MAX inhabitants.
4297+
#if SWIFT_OBJC_INTEROP
42924298
return (LeastValidPointerValue >> ObjCReservedLowBits) > INT_MAX
42934299
? (unsigned)INT_MAX
42944300
: (unsigned)(LeastValidPointerValue >> ObjCReservedLowBits);
4301+
#else
4302+
return (LeastValidPointerValue) > INT_MAX
4303+
? unsigned(INT_MAX)
4304+
: unsigned(LeastValidPointerValue);
4305+
#endif
42954306
}
42964307

42974308
/// Calculate the numeric index of an extra inhabitant of a function

lib/IRGen/ExtraInhabitants.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ using namespace swift;
2424
using namespace irgen;
2525

2626
static unsigned getNumLowObjCReservedBits(IRGenModule &IGM) {
27+
if (!IGM.ObjCInterop)
28+
return 0;
29+
2730
// Get the index of the first non-reserved bit.
2831
SpareBitVector ObjCMask = IGM.TargetInfo.ObjCPointerReservedBits;
2932
ObjCMask.flipAll();

test/IRGen/enum.sil

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
// Please put -enable-objc-interop tests in enum_objc.sil
2-
// RUN: %target-swift-frontend -assume-parsing-unqualified-ownership-sil %s -gnone -emit-ir -disable-objc-interop | %FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-%target-ptrsize --check-prefix=CHECK-%target-runtime-%target-ptrsize
1+
// #if directives don't work with SIL keywords, therefore please put ObjC tests
2+
// in `enum_objc.sil`.
3+
4+
// RUN: %target-swift-frontend -assume-parsing-unqualified-ownership-sil %s -gnone -emit-ir -disable-objc-interop | %FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-%target-ptrsize
35

46
// REQUIRES: CPU=i386 || CPU=x86_64
57

@@ -1120,8 +1122,8 @@ enum SinglePayloadClass {
11201122
// CHECK-64: entry:
11211123
// CHECK-64: switch i64 %0, label {{%.*}} [
11221124
// CHECK-64: i64 0, label {{%.*}}
1123-
// CHECK-64: i64 2, label {{%.*}}
1124-
// CHECK-64: i64 4, label {{%.*}}
1125+
// CHECK-64: i64 1, label {{%.*}}
1126+
// CHECK-64: i64 2, label {{%.*}}
11251127
// CHECK-64: ]
11261128
// CHECK-64: ; <label>
11271129
// CHECK-64: inttoptr [[WORD]] %0 to %T4enum1CC*
@@ -1163,8 +1165,8 @@ enum SinglePayloadClassProtocol {
11631165
// CHECK-64: define{{( dllexport)?}}{{( protected)?}} swiftcc void @single_payload_class_protocol_switch(i64, i64) {{.*}} {
11641166
// CHECK-64: switch i64 %0, label {{%.*}} [
11651167
// CHECK-64: i64 0, label {{%.*}}
1168+
// CHECK-64: i64 1, label {{%.*}}
11661169
// CHECK-64: i64 2, label {{%.*}}
1167-
// CHECK-64: i64 4, label {{%.*}}
11681170
// CHECK-64: ]
11691171

11701172
// CHECK-64: inttoptr i64 %0 to %swift.refcounted*
@@ -2437,7 +2439,7 @@ entry(%0 : $DynamicSingleton<NoPayloads>):
24372439
// Check that payloads get properly masked in nested single-payload enums.
24382440
// rdar://problem/18841262
24392441
// CHECK-64-LABEL: define{{( dllexport)?}}{{( protected)?}} swiftcc i1 @optional_optional_class_protocol(i64, i64)
2440-
// CHECK-64: icmp eq i64 %0, 2
2442+
// CHECK-64: icmp eq i64 %0, 1
24412443
// CHECK-32-LABEL: define{{( dllexport)?}}{{( protected)?}} swiftcc i1 @optional_optional_class_protocol(i32, i32)
24422444
// CHECK-32: icmp eq i32 %0, 1
24432445
enum Optionable<T> {
@@ -2458,7 +2460,7 @@ struct ContainsUnownedObjC {
24582460
unowned let x: C
24592461
}
24602462
// CHECK-LABEL: define {{.*}} @optional_unowned() {{.*}} {
2461-
// CHECK-64: ret { [[WORD]], [[WORD]] } { [[WORD]] 0, [[WORD]] 2 }
2463+
// CHECK-64: ret { [[WORD]], [[WORD]] } { [[WORD]] 0, [[WORD]] 1 }
24622464
// CHECK-32: ret { [[WORD]], [[WORD]] } { [[WORD]] 0, [[WORD]] 1 }
24632465
sil @optional_unowned : $@convention(thin) () -> (Optionable<ContainsUnowned>, Optionable<Optionable<ContainsUnowned>>) {
24642466
entry:
@@ -2468,7 +2470,7 @@ entry:
24682470
return %t : $(Optionable<ContainsUnowned>, Optionable<Optionable<ContainsUnowned>>)
24692471
}
24702472
// CHECK-LABEL: define {{.*}} @optional_unowned_objc() {{.*}} {
2471-
// CHECK-64: ret { [[WORD]], [[WORD]] } { [[WORD]] 0, [[WORD]] 2 }
2473+
// CHECK-64: ret { [[WORD]], [[WORD]] } { [[WORD]] 0, [[WORD]] 1 }
24722474
// CHECK-32: ret { [[WORD]], [[WORD]] } { [[WORD]] 0, [[WORD]] 1 }
24732475
sil @optional_unowned_objc : $@convention(thin) () -> (Optionable<ContainsUnownedObjC>, Optionable<Optionable<ContainsUnownedObjC>>) {
24742476
entry:

test/IRGen/enum_objc.sil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swift-frontend -assume-parsing-unqualified-ownership-sil %s -gnone -emit-ir -disable-objc-attr-requires-foundation-module -enable-objc-interop | %FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-%target-ptrsize --check-prefix=CHECK-%target-runtime-%target-ptrsize
1+
// RUN: %target-swift-frontend -assume-parsing-unqualified-ownership-sil %s -gnone -emit-ir -disable-objc-attr-requires-foundation-module -enable-objc-interop | %FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-%target-ptrsize
22

33
// REQUIRES: CPU=i386 || CPU=x86_64
44

test/IRGen/enum_value_semantics.sil

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// RUN: %target-swift-frontend -assume-parsing-unqualified-ownership-sil %s -gnone -emit-ir | %FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-%target-ptrsize
1+
// RUN: %target-swift-frontend -assume-parsing-unqualified-ownership-sil %s -gnone -emit-ir -enable-objc-interop | %FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-%target-ptrsize --check-prefix=CHECK-objc --check-prefix=CHECK-objc-%target-ptrsize --check-prefix=CHECK-%target-os --check-prefix=CHECK-objc-%target-os
2+
// RUN: %target-swift-frontend -assume-parsing-unqualified-ownership-sil %s -gnone -emit-ir -disable-objc-interop | %FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-%target-ptrsize --check-prefix=CHECK-native --check-prefix=CHECK-native-%target-ptrsize --check-prefix=CHECK-%target-os --check-prefix=CHECK-native-%target-os
23

34
// REQUIRES: CPU=x86_64
45

@@ -134,9 +135,16 @@ enum GenericFixedLayout<T> {
134135
// -- 0x250007
135136
// CHECK: i8* inttoptr (i64 2424839 to i8*),
136137
// CHECK: i8* inttoptr (i64 8 to i8*),
137-
// -- on Darwin, first 4GB are unmapped: 0x7ffffffc
138-
// -- on Linux, only safe to assume first 4KB: 0x7fd
139-
// CHECK: i8* inttoptr (i64 {{2045|2147483644}} to i8*)
138+
// -- On Darwin, the first 4 GiB are unmapped: 0x7ffffffc
139+
// -- Otherwise, one can only assume the first page (4 KiB) is unmapped: 0xffd
140+
// CHECK-ios: i8* inttoptr (i64 2147483644 to i8*)
141+
// CHECK-macosx: i8* inttoptr (i64 2147483644 to i8*)
142+
// CHECK-watchos: i8* inttoptr (i64 2147483644 to i8*)
143+
// CHECK-darwin: i8* inttoptr (i64 2147483644 to i8*)
144+
// CHECK-objc-linux-gnu: i8* inttoptr (i64 2045 to i8*)
145+
// CHECK-native-linux-gnu: i8* inttoptr (i64 4093 to i8*)
146+
// CHECK-objc-windows: i8* inttoptr (i64 2045 to i8*)
147+
// CHECK-native-windows: i8* inttoptr (i64 4093 to i8*)
140148
// CHECK: i8* bitcast (void (%swift.opaque*, i32, %swift.type*)* @"$S20enum_value_semantics23SinglePayloadNontrivialOwxs" to i8*)
141149
// CHECK: i8* bitcast (i32 (%swift.opaque*, %swift.type*)* @"$S20enum_value_semantics23SinglePayloadNontrivialOwxg" to i8*)
142150
// CHECK: i8* bitcast (i32 (%swift.opaque*, %swift.type*)* @"$S20enum_value_semantics23SinglePayloadNontrivialOwug" to i8*),
@@ -277,8 +285,10 @@ bb0(%0 : $SinglePayloadNontrivial):
277285
// CHECK-NEXT: [[PAYLOAD:%.*]] = load i64, i64* [[PAYLOAD_ADDR]], align 8
278286
// CHECK-NEXT: switch i64 %2, label %[[RELEASE_PAYLOAD:[0-9]+]] [
279287
// CHECK: i64 0, label %[[DONE:[0-9]+]]
280-
// CHECK: i64 2, label %[[DONE]]
281-
// CHECK: i64 4, label %[[DONE]]
288+
// CHECK-native: i64 1, label %[[DONE]]
289+
// CHECK-native: i64 2, label %[[DONE]]
290+
// CHECK-objc: i64 2, label %[[DONE]]
291+
// CHECK-objc: i64 4, label %[[DONE]]
282292
// CHECK: ]
283293

284294
// CHECK: ; <label>:[[RELEASE_PAYLOAD]]

test/IRGen/enum_value_semantics_special_cases.sil

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swift-frontend -assume-parsing-unqualified-ownership-sil %s -emit-ir | %FileCheck %s
1+
// RUN: %target-swift-frontend -assume-parsing-unqualified-ownership-sil %s -emit-ir | %FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-%target-runtime
22

33
// REQUIRES: CPU=x86_64
44

@@ -134,7 +134,8 @@ enum MultipleEmptyRefcounted {
134134
// CHECK: %2 = load i64, i64* %1, align 8
135135
// CHECK: switch i64 %2, label %3 [
136136
// CHECK: i64 0, label %5
137-
// CHECK: i64 2, label %5
137+
// CHECK-native: i64 1, label %5
138+
// CHECK-objc: i64 2, label %5
138139
// CHECK: ]
139140
// CHECK: ; <label>:3: ; preds = %entry
140141
// CHECK: %4 = bitcast %T34enum_value_semantics_special_cases23MultipleEmptyRefcountedO* %0 to %swift.refcounted**

0 commit comments

Comments
 (0)