Skip to content

Commit 38e07a6

Browse files
Merge pull request #11897 from aschwaighofer/runtime_return_dest_from_weak
runtime: return the destination address in swift_weakInit/Assign/Copy…
2 parents 6e21af0 + d83baca commit 38e07a6

File tree

9 files changed

+120
-50
lines changed

9 files changed

+120
-50
lines changed

include/swift/Runtime/HeapObject.h

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -673,15 +673,17 @@ class WeakReference;
673673
///
674674
/// \param ref - never null
675675
/// \param value - can be null
676+
/// \return ref
676677
SWIFT_RUNTIME_EXPORT
677-
void swift_weakInit(WeakReference *ref, HeapObject *value);
678+
WeakReference *swift_weakInit(WeakReference *ref, HeapObject *value);
678679

679680
/// Assign a new value to a weak reference.
680681
///
681682
/// \param ref - never null
682683
/// \param value - can be null
684+
/// \return ref
683685
SWIFT_RUNTIME_EXPORT
684-
void swift_weakAssign(WeakReference *ref, HeapObject *value);
686+
WeakReference *swift_weakAssign(WeakReference *ref, HeapObject *value);
685687

686688
/// Load a value from a weak reference. If the current value is a
687689
/// non-null object that has begun deallocation, returns null;
@@ -710,29 +712,33 @@ void swift_weakDestroy(WeakReference *ref);
710712
///
711713
/// \param dest - never null, but can refer to a null object
712714
/// \param src - never null, but can refer to a null object
715+
/// \return dest
713716
SWIFT_RUNTIME_EXPORT
714-
void swift_weakCopyInit(WeakReference *dest, WeakReference *src);
717+
WeakReference *swift_weakCopyInit(WeakReference *dest, WeakReference *src);
715718

716719
/// Take initialize a weak reference.
717720
///
718721
/// \param dest - never null, but can refer to a null object
719722
/// \param src - never null, but can refer to a null object
723+
/// \return dest
720724
SWIFT_RUNTIME_EXPORT
721-
void swift_weakTakeInit(WeakReference *dest, WeakReference *src);
725+
WeakReference *swift_weakTakeInit(WeakReference *dest, WeakReference *src);
722726

723727
/// Copy assign a weak reference.
724728
///
725729
/// \param dest - never null, but can refer to a null object
726730
/// \param src - never null, but can refer to a null object
731+
/// \return dest
727732
SWIFT_RUNTIME_EXPORT
728-
void swift_weakCopyAssign(WeakReference *dest, WeakReference *src);
733+
WeakReference *swift_weakCopyAssign(WeakReference *dest, WeakReference *src);
729734

730735
/// Take assign a weak reference.
731736
///
732737
/// \param dest - never null, but can refer to a null object
733738
/// \param src - never null, but can refer to a null object
739+
/// \return dest
734740
SWIFT_RUNTIME_EXPORT
735-
void swift_weakTakeAssign(WeakReference *dest, WeakReference *src);
741+
WeakReference *swift_weakTakeAssign(WeakReference *dest, WeakReference *src);
736742

737743
/*****************************************************************************/
738744
/************************* OTHER REFERENCE-COUNTING **************************/

include/swift/Runtime/RuntimeFunctions.def

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -464,17 +464,17 @@ FUNCTION(NativeWeakDestroy, swift_weakDestroy, DefaultCC,
464464
ARGS(WeakReferencePtrTy),
465465
ATTRS(NoUnwind))
466466

467-
// void swift_weakInit(WeakReference *object, void *value);
467+
// WeakReference *swift_weakInit(WeakReference *object, void *value);
468468
FUNCTION(NativeWeakInit, swift_weakInit, DefaultCC,
469-
RETURNS(VoidTy),
469+
RETURNS(WeakReferencePtrTy),
470470
ARGS(WeakReferencePtrTy, RefCountedPtrTy),
471-
ATTRS(NoUnwind))
471+
ATTRS(NoUnwind, FirstParamReturned))
472472

473-
// void swift_weakAssign(WeakReference *object, void *value);
473+
// WeakReferencePtr *swift_weakAssign(WeakReference *object, void *value);
474474
FUNCTION(NativeWeakAssign, swift_weakAssign, DefaultCC,
475-
RETURNS(VoidTy),
475+
RETURNS(WeakReferencePtrTy),
476476
ARGS(WeakReferencePtrTy, RefCountedPtrTy),
477-
ATTRS(NoUnwind))
477+
ATTRS(NoUnwind, FirstParamReturned))
478478

479479
// void *swift_weakLoadStrong(WeakReference *object);
480480
FUNCTION(NativeWeakLoadStrong, swift_weakLoadStrong,DefaultCC,
@@ -488,29 +488,29 @@ FUNCTION(NativeWeakTakeStrong, swift_weakTakeStrong,DefaultCC,
488488
ARGS(WeakReferencePtrTy),
489489
ATTRS(NoUnwind))
490490

491-
// void swift_weakCopyInit(WeakReference *dest, WeakReference *src);
491+
// WeakReference *swift_weakCopyInit(WeakReference *dest, WeakReference *src);
492492
FUNCTION(NativeWeakCopyInit, swift_weakCopyInit, DefaultCC,
493-
RETURNS(VoidTy),
493+
RETURNS(WeakReferencePtrTy),
494494
ARGS(WeakReferencePtrTy, WeakReferencePtrTy),
495-
ATTRS(NoUnwind))
495+
ATTRS(NoUnwind, FirstParamReturned))
496496

497-
// void swift_weakTakeInit(WeakReference *dest, WeakReference *src);
497+
// WeakReference *swift_weakTakeInit(WeakReference *dest, WeakReference *src);
498498
FUNCTION(NativeWeakTakeInit, swift_weakTakeInit, DefaultCC,
499-
RETURNS(VoidTy),
499+
RETURNS(WeakReferencePtrTy),
500500
ARGS(WeakReferencePtrTy, WeakReferencePtrTy),
501-
ATTRS(NoUnwind))
501+
ATTRS(NoUnwind, FirstParamReturned))
502502

503-
// void swift_weakCopyAssign(WeakReference *dest, WeakReference *src);
503+
// WeakReference *swift_weakCopyAssign(WeakReference *dest, WeakReference *src);
504504
FUNCTION(NativeWeakCopyAssign, swift_weakCopyAssign, DefaultCC,
505-
RETURNS(VoidTy),
505+
RETURNS(WeakReferencePtrTy),
506506
ARGS(WeakReferencePtrTy, WeakReferencePtrTy),
507-
ATTRS(NoUnwind))
507+
ATTRS(NoUnwind, FirstParamReturned))
508508

509-
// void swift_weakTakeAssign(WeakReference *dest, WeakReference *src);
509+
// WeakReference *swift_weakTakeAssign(WeakReference *dest, WeakReference *src);
510510
FUNCTION(NativeWeakTakeAssign, swift_weakTakeAssign, DefaultCC,
511-
RETURNS(VoidTy),
511+
RETURNS(WeakReferencePtrTy),
512512
ARGS(WeakReferencePtrTy, WeakReferencePtrTy),
513-
ATTRS(NoUnwind))
513+
ATTRS(NoUnwind, FirstParamReturned))
514514

515515
// void swift_unknownWeakDestroy(WeakReference *object);
516516
FUNCTION(UnknownWeakDestroy, swift_unknownWeakDestroy, DefaultCC,

lib/IRGen/IRGenModule.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,7 @@ namespace RuntimeConstants {
428428
const auto NoReturn = llvm::Attribute::NoReturn;
429429
const auto NoUnwind = llvm::Attribute::NoUnwind;
430430
const auto ZExt = llvm::Attribute::ZExt;
431+
const auto FirstParamReturned = llvm::Attribute::Returned;
431432
} // namespace RuntimeConstants
432433

433434
// We don't use enough attributes to justify generalizing the
@@ -436,6 +437,11 @@ namespace RuntimeConstants {
436437
static bool isReturnAttribute(llvm::Attribute::AttrKind Attr) {
437438
return Attr == llvm::Attribute::ZExt;
438439
}
440+
// Similar to the 'return' attribute we assume that the 'returned' attributed is
441+
// associated with the first function parameter.
442+
static bool isReturnedAttribute(llvm::Attribute::AttrKind Attr) {
443+
return Attr == llvm::Attribute::Returned;
444+
}
439445

440446
llvm::Constant *swift::getRuntimeFn(llvm::Module &Module,
441447
llvm::Constant *&cache,
@@ -471,15 +477,19 @@ llvm::Constant *swift::getRuntimeFn(llvm::Module &Module,
471477

472478
llvm::AttrBuilder buildFnAttr;
473479
llvm::AttrBuilder buildRetAttr;
480+
llvm::AttrBuilder buildFirstParamAttr;
474481

475482
for (auto Attr : attrs) {
476483
if (isReturnAttribute(Attr))
477484
buildRetAttr.addAttribute(Attr);
485+
else if (isReturnedAttribute(Attr))
486+
buildFirstParamAttr.addAttribute(Attr);
478487
else
479488
buildFnAttr.addAttribute(Attr);
480489
}
481490
fn->addAttributes(llvm::AttributeList::FunctionIndex, buildFnAttr);
482491
fn->addAttributes(llvm::AttributeList::ReturnIndex, buildRetAttr);
492+
fn->addParamAttrs(0, buildFirstParamAttr);
483493
}
484494

485495
return cache;

stdlib/public/runtime/HeapObject.cpp

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -829,13 +829,14 @@ void swift::swift_deallocObject(HeapObject *object, size_t allocatedSize,
829829
}
830830
}
831831

832-
833-
void swift::swift_weakInit(WeakReference *ref, HeapObject *value) {
832+
WeakReference *swift::swift_weakInit(WeakReference *ref, HeapObject *value) {
834833
ref->nativeInit(value);
834+
return ref;
835835
}
836836

837-
void swift::swift_weakAssign(WeakReference *ref, HeapObject *value) {
837+
WeakReference *swift::swift_weakAssign(WeakReference *ref, HeapObject *value) {
838838
ref->nativeAssign(value);
839+
return ref;
839840
}
840841

841842
HeapObject *swift::swift_weakLoadStrong(WeakReference *ref) {
@@ -850,19 +851,27 @@ void swift::swift_weakDestroy(WeakReference *ref) {
850851
ref->nativeDestroy();
851852
}
852853

853-
void swift::swift_weakCopyInit(WeakReference *dest, WeakReference *src) {
854+
WeakReference *swift::swift_weakCopyInit(WeakReference *dest,
855+
WeakReference *src) {
854856
dest->nativeCopyInit(src);
857+
return dest;
855858
}
856859

857-
void swift::swift_weakTakeInit(WeakReference *dest, WeakReference *src) {
860+
WeakReference *swift::swift_weakTakeInit(WeakReference *dest,
861+
WeakReference *src) {
858862
dest->nativeTakeInit(src);
863+
return dest;
859864
}
860865

861-
void swift::swift_weakCopyAssign(WeakReference *dest, WeakReference *src) {
866+
WeakReference *swift::swift_weakCopyAssign(WeakReference *dest,
867+
WeakReference *src) {
862868
dest->nativeCopyAssign(src);
869+
return dest;
863870
}
864871

865-
void swift::swift_weakTakeAssign(WeakReference *dest, WeakReference *src) {
872+
WeakReference *swift::swift_weakTakeAssign(WeakReference *dest,
873+
WeakReference *src) {
866874
dest->nativeTakeAssign(src);
875+
return dest;
867876
}
868877

test/IRGen/existentials.sil

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,15 @@ entry(%w : $*@sil_weak CP?, %a : $CP?):
4444
// CHECK: [[DEST_WITNESS_ADDR:%.*]] = getelementptr inbounds { %swift.weak, i8** }, { %swift.weak, i8** }* %0, i32 0, i32 1
4545
// CHECK: store i8** [[SRC_WITNESS]], i8*** [[DEST_WITNESS_ADDR]]
4646
// CHECK: [[DEST_REF_ADDR:%.*]] = getelementptr inbounds { %swift.weak, i8** }, { %swift.weak, i8** }* %0, i32 0, i32 0
47-
// CHECK: call void @swift_weakInit(%swift.weak* [[DEST_REF_ADDR]], %swift.refcounted* [[SRC_REF]])
47+
// CHECK: call %swift.weak* @swift_weakInit(%swift.weak* [[DEST_REF_ADDR]], %swift.refcounted* [[SRC_REF]])
4848
store_weak %a to [initialization] %w : $*@sil_weak CP?
4949

5050
// CHECK: [[SRC_REF:%.*]] = inttoptr {{.*}} %swift.refcounted*
5151
// CHECK: [[SRC_WITNESS:%.*]] = inttoptr {{.*}} i8**
5252
// CHECK: [[DEST_WITNESS_ADDR:%.*]] = getelementptr inbounds { %swift.weak, i8** }, { %swift.weak, i8** }* %0, i32 0, i32 1
5353
// CHECK: store i8** [[SRC_WITNESS]], i8*** [[DEST_WITNESS_ADDR]]
5454
// CHECK: [[DEST_REF_ADDR:%.*]] = getelementptr inbounds { %swift.weak, i8** }, { %swift.weak, i8** }* %0, i32 0, i32 0
55-
// CHECK: call void @swift_weakAssign(%swift.weak* [[DEST_REF_ADDR]], %swift.refcounted* [[SRC_REF]])
55+
// CHECK: call %swift.weak* @swift_weakAssign(%swift.weak* [[DEST_REF_ADDR]], %swift.refcounted* [[SRC_REF]])
5656
store_weak %a to %w : $*@sil_weak CP?
5757

5858
// CHECK: [[SRC_REF_ADDR:%.*]] = getelementptr inbounds { %swift.weak, i8** }, { %swift.weak, i8** }* %0, i32 0, i32 0
@@ -69,7 +69,7 @@ entry(%w : $*@sil_weak CP?, %a : $CP?):
6969

7070
// CHECK: [[DEST_REF_ADDR:%.*]] = getelementptr inbounds { %swift.weak, i8** }, { %swift.weak, i8** }* [[V]], i32 0, i32 0
7171
// CHECK: [[SRC_REF_ADDR:%.*]] = getelementptr inbounds { %swift.weak, i8** }, { %swift.weak, i8** }* %0, i32 0, i32 0
72-
// CHECK: call void @swift_weakTakeInit(%swift.weak* [[DEST_REF_ADDR]], %swift.weak* [[SRC_REF_ADDR]])
72+
// CHECK: call %swift.weak* @swift_weakTakeInit(%swift.weak* [[DEST_REF_ADDR]], %swift.weak* [[SRC_REF_ADDR]])
7373
// CHECK: [[SRC_WITNESS_ADDR:%.*]] = getelementptr inbounds { %swift.weak, i8** }, { %swift.weak, i8** }* %0, i32 0, i32 1
7474
// CHECK: [[WITNESS:%.*]] = load i8**, i8*** [[SRC_WITNESS_ADDR]], align 8
7575
// CHECK: [[DEST_WITNESS_ADDR:%.*]] = getelementptr inbounds { %swift.weak, i8** }, { %swift.weak, i8** }* [[V]], i32 0, i32 1
@@ -78,7 +78,7 @@ entry(%w : $*@sil_weak CP?, %a : $CP?):
7878

7979
// CHECK: [[DEST_REF_ADDR:%.*]] = getelementptr inbounds { %swift.weak, i8** }, { %swift.weak, i8** }* [[V]], i32 0, i32 0
8080
// CHECK: [[SRC_REF_ADDR:%.*]] = getelementptr inbounds { %swift.weak, i8** }, { %swift.weak, i8** }* %0, i32 0, i32 0
81-
// CHECK: call void @swift_weakTakeAssign(%swift.weak* [[DEST_REF_ADDR]], %swift.weak* [[SRC_REF_ADDR]])
81+
// CHECK: call %swift.weak* @swift_weakTakeAssign(%swift.weak* [[DEST_REF_ADDR]], %swift.weak* [[SRC_REF_ADDR]])
8282
// CHECK: [[SRC_WITNESS_ADDR:%.*]] = getelementptr inbounds { %swift.weak, i8** }, { %swift.weak, i8** }* %0, i32 0, i32 1
8383
// CHECK: [[WITNESS:%.*]] = load i8**, i8*** [[SRC_WITNESS_ADDR]], align 8
8484
// CHECK: [[DEST_WITNESS_ADDR:%.*]] = getelementptr inbounds { %swift.weak, i8** }, { %swift.weak, i8** }* [[V]], i32 0, i32 1
@@ -87,7 +87,7 @@ entry(%w : $*@sil_weak CP?, %a : $CP?):
8787

8888
// CHECK: [[DEST_REF_ADDR:%.*]] = getelementptr inbounds { %swift.weak, i8** }, { %swift.weak, i8** }* [[V]], i32 0, i32 0
8989
// CHECK: [[SRC_REF_ADDR:%.*]] = getelementptr inbounds { %swift.weak, i8** }, { %swift.weak, i8** }* %0, i32 0, i32 0
90-
// CHECK: call void @swift_weakCopyInit(%swift.weak* [[DEST_REF_ADDR]], %swift.weak* [[SRC_REF_ADDR]])
90+
// CHECK: call %swift.weak* @swift_weakCopyInit(%swift.weak* [[DEST_REF_ADDR]], %swift.weak* [[SRC_REF_ADDR]])
9191
// CHECK: [[SRC_WITNESS_ADDR:%.*]] = getelementptr inbounds { %swift.weak, i8** }, { %swift.weak, i8** }* %0, i32 0, i32 1
9292
// CHECK: [[WITNESS:%.*]] = load i8**, i8*** [[SRC_WITNESS_ADDR]], align 8
9393
// CHECK: [[DEST_WITNESS_ADDR:%.*]] = getelementptr inbounds { %swift.weak, i8** }, { %swift.weak, i8** }* [[V]], i32 0, i32 1
@@ -96,7 +96,7 @@ entry(%w : $*@sil_weak CP?, %a : $CP?):
9696

9797
// CHECK: [[DEST_REF_ADDR:%.*]] = getelementptr inbounds { %swift.weak, i8** }, { %swift.weak, i8** }* [[V]], i32 0, i32 0
9898
// CHECK: [[SRC_REF_ADDR:%.*]] = getelementptr inbounds { %swift.weak, i8** }, { %swift.weak, i8** }* %0, i32 0, i32 0
99-
// CHECK: call void @swift_weakCopyAssign(%swift.weak* [[DEST_REF_ADDR]], %swift.weak* [[SRC_REF_ADDR]])
99+
// CHECK: call %swift.weak* @swift_weakCopyAssign(%swift.weak* [[DEST_REF_ADDR]], %swift.weak* [[SRC_REF_ADDR]])
100100
// CHECK: [[SRC_WITNESS_ADDR:%.*]] = getelementptr inbounds { %swift.weak, i8** }, { %swift.weak, i8** }* %0, i32 0, i32 1
101101
// CHECK: [[WITNESS:%.*]] = load i8**, i8*** [[SRC_WITNESS_ADDR]], align 8
102102
// CHECK: [[DEST_WITNESS_ADDR:%.*]] = getelementptr inbounds { %swift.weak, i8** }, { %swift.weak, i8** }* [[V]], i32 0, i32 1

test/IRGen/weak.sil

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// RUN: %target-swift-frontend -assume-parsing-unqualified-ownership-sil -emit-ir %s | %FileCheck %s
2+
// RUN: %target-swift-frontend -assume-parsing-unqualified-ownership-sil -O -S %s | %FileCheck %s --check-prefix=TAILCALL
23

34
// REQUIRES: CPU=x86_64
45
// XFAIL: linux
@@ -15,15 +16,15 @@ sil_stage canonical
1516

1617
import Swift
1718

18-
class C {}
19+
public class C {}
1920
sil_vtable C {}
2021
sil @_T04weak1CCfD : $@convention(method) (C) -> ()
2122

2223
protocol P : class {
2324
func explode()
2425
}
2526

26-
struct A {
27+
public struct A {
2728
weak var x : C?
2829
}
2930

@@ -46,7 +47,7 @@ bb0(%0 : $*A, %1 : $Optional<C>):
4647
// CHECK-NEXT: [[T0:%.*]] = call [[C]]* bitcast ([[REF]]* ([[WEAK]]*)* @swift_weakLoadStrong to [[C]]* ([[WEAK]]*)*)([[WEAK]]* [[X]])
4748
// CHECK-NEXT: %3 = ptrtoint %T4weak1CC* %2 to i64
4849
// CHECK-NEXT: %4 = inttoptr
49-
// CHECK-NEXT: call void bitcast (void ([[WEAK]]*, [[REF]]*)* @swift_weakAssign to void ([[WEAK]]*, [[C]]*)*)([[WEAK]]* [[X]], [[C]]* %4)
50+
// CHECK-NEXT: call void bitcast ([[WEAK]]* ([[WEAK]]*, [[REF]]*)* @swift_weakAssign to void ([[WEAK]]*, [[C]]*)*)([[WEAK]]* [[X]], [[C]]* %4)
5051
// CHECK-NEXT: %5 = inttoptr i64 %3 to %swift.refcounted*
5152
// CHECK-NEXT: call void @swift_rt_swift_release([[REF]]* %5)
5253
// CHECK-NEXT: ret void
@@ -109,43 +110,64 @@ bb0(%0 : $Optional<P>):
109110
// CHECK-NEXT: [[SRC:%.*]] = bitcast [[BUFFER]]* [[SRCBUF]] to [[A]]*
110111
// CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds [[A]], [[A]]* [[DEST]], i32 0, i32 0
111112
// CHECK-NEXT: [[T1:%.*]] = getelementptr inbounds [[A]], [[A]]* [[SRC]], i32 0, i32 0
112-
// CHECK-NEXT: call void @swift_weakCopyInit([[WEAK]]* [[T0]], [[WEAK]]* [[T1]])
113+
// CHECK-NEXT: call [[WEAK]]* @swift_weakCopyInit([[WEAK]]* [[T0]], [[WEAK]]* [[T1]])
113114
// CHECK-NEXT: [[T0:%.*]] = bitcast [[A]]* [[DEST]] to [[OPAQUE]]*
114115
// CHECK-NEXT: ret [[OPAQUE]]* [[T0]]
115116

117+
// TAILCALL: __T04weak1AVwCP:
118+
// TAILCALL: jmp _swift_weakCopyInit
119+
116120
// destroy
117121
// CHECK: define linkonce_odr hidden void @_T04weak1AVwxx([[OPAQUE]]* noalias [[ARG:%.*]], [[TYPE]]*
118122
// CHECK: [[T0:%.*]] = bitcast [[OPAQUE]]* [[ARG]] to [[A]]*
119123
// CHECK-NEXT: [[T1:%.*]] = getelementptr inbounds [[A]], [[A]]* [[T0]], i32 0, i32 0
120124
// CHECK-NEXT: call void @swift_weakDestroy([[WEAK]]* [[T1]])
121125
// CHECK-NEXT: ret void
122126

127+
// TAILCALL: __T04weak1AVwxx:
128+
// TAILCALL: jmp _swift_weakDestroy
129+
123130
// initializeWithCopy
124131
// CHECK: define linkonce_odr hidden [[OPAQUE]]* @_T04weak1AVwcp([[OPAQUE]]* noalias [[DEST_OPQ:%.*]], [[OPAQUE]]* noalias [[SRC_OPQ:%.*]], [[TYPE]]*
125132
// CHECK: [[DEST:%.*]] = bitcast [[OPAQUE]]* [[DEST_OPQ]] to [[A]]*
126133
// CHECK-NEXT: [[SRC:%.*]] = bitcast [[OPAQUE]]* [[SRC_OPQ]] to [[A]]*
127134
// CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds [[A]], [[A]]* [[DEST]], i32 0, i32 0
128135
// CHECK-NEXT: [[T1:%.*]] = getelementptr inbounds [[A]], [[A]]* [[SRC]], i32 0, i32 0
129-
// CHECK-NEXT: call void @swift_weakCopyInit([[WEAK]]* [[T0]], [[WEAK]]* [[T1]])
136+
// CHECK-NEXT: call [[WEAK]]* @swift_weakCopyInit([[WEAK]]* [[T0]], [[WEAK]]* [[T1]])
130137
// CHECK-NEXT: [[T0:%.*]] = bitcast [[A]]* [[DEST]] to [[OPAQUE]]*
131138
// CHECK-NEXT: ret [[OPAQUE]]* [[T0]]
132139

140+
// TAILCALL: __T04weak1AVwcp:
141+
// TAILCALL: jmp _swift_weakCopyInit
142+
133143
// assignWithCopy
134144
// CHECK: define linkonce_odr hidden [[OPAQUE]]* @_T04weak1AVwca([[OPAQUE]]* [[DEST_OPQ:%.*]], [[OPAQUE]]* [[SRC_OPQ:%.*]], [[TYPE]]*
135145
// CHECK: [[DEST:%.*]] = bitcast [[OPAQUE]]* [[DEST_OPQ]] to [[A]]*
136146
// CHECK-NEXT: [[SRC:%.*]] = bitcast [[OPAQUE]]* [[SRC_OPQ]] to [[A]]*
137147
// CHECK-NEXT: [[DEST_X:%.*]] = getelementptr inbounds [[A]], [[A]]* [[DEST]], i32 0, i32 0
138148
// CHECK-NEXT: [[SRC_X:%.*]] = getelementptr inbounds [[A]], [[A]]* [[SRC]], i32 0, i32 0
139-
// CHECK-NEXT: call void @swift_weakCopyAssign([[WEAK]]* [[DEST_X]], [[WEAK]]* [[SRC_X]])
149+
// CHECK-NEXT: call [[WEAK]]* @swift_weakCopyAssign([[WEAK]]* [[DEST_X]], [[WEAK]]* [[SRC_X]])
140150
// CHECK-NEXT: [[T0:%.*]] = bitcast [[A]]* [[DEST]] to [[OPAQUE]]*
141151
// CHECK-NEXT: ret [[OPAQUE]]* [[T0]]
142152

153+
// TAILCALL: __T04weak1AVwca:
154+
// TAILCALL: jmp _swift_weakCopyAssign
155+
143156
// assignWithTake
144157
// CHECK: define linkonce_odr hidden [[OPAQUE]]* @_T04weak1AVwta([[OPAQUE]]* noalias [[DEST_OPQ:%.*]], [[OPAQUE]]* noalias [[SRC_OPQ:%.*]], [[TYPE]]*
145158
// CHECK: [[DEST:%.*]] = bitcast [[OPAQUE]]* [[DEST_OPQ]] to [[A]]*
146159
// CHECK-NEXT: [[SRC:%.*]] = bitcast [[OPAQUE]]* [[SRC_OPQ]] to [[A]]*
147160
// CHECK-NEXT: [[DEST_X:%.*]] = getelementptr inbounds [[A]], [[A]]* [[DEST]], i32 0, i32 0
148161
// CHECK-NEXT: [[SRC_X:%.*]] = getelementptr inbounds [[A]], [[A]]* [[SRC]], i32 0, i32 0
149-
// CHECK-NEXT: call void @swift_weakTakeAssign([[WEAK]]* [[DEST_X]], [[WEAK]]* [[SRC_X]])
162+
// CHECK-NEXT: call [[WEAK]]* @swift_weakTakeAssign([[WEAK]]* [[DEST_X]], [[WEAK]]* [[SRC_X]])
150163
// CHECK-NEXT: [[T0:%.*]] = bitcast [[A]]* [[DEST]] to [[OPAQUE]]*
151164
// CHECK-NEXT: ret [[OPAQUE]]* [[T0]]
165+
166+
// TAILCALL: __T04weak1AVwtk:
167+
// TAILCALL: jmp _swift_weakTakeInit
168+
169+
// TAILCALL: __T04weak1AVwta:
170+
// TAILCALL: jmp _swift_weakTakeAssign
171+
172+
// TAILCALL: __T04weak1AVwTK:
173+
// TAILCALL: jmp _swift_weakTakeInit

test/IRGen/weak_class_protocol.sil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ protocol Foo: class { }
1515
// CHECK: store i8** [[WTABLE]], i8*** [[WTABLE_SLOT]], align 8
1616
// CHECK: [[INSTANCE_SLOT:%.*]] = getelementptr inbounds { %swift.weak, i8** }, { %swift.weak, i8** }* %0, i32 0, i32 0
1717
// CHECK-objc: call void @swift_unknownWeakAssign(%swift.weak* [[INSTANCE_SLOT]], %objc_object* [[INSTANCE]]) {{#[0-9]+}}
18-
// CHECK-native: call void @swift_weakAssign(%swift.weak* [[INSTANCE_SLOT]], %swift.refcounted* [[INSTANCE]]) {{#[0-9]+}}
18+
// CHECK-native: call %swift.weak* @swift_weakAssign(%swift.weak* [[INSTANCE_SLOT]], %swift.refcounted* [[INSTANCE]]) {{#[0-9]+}}
1919
// CHECK: ret void
2020
// CHECK: }
2121
sil @store_weak : $@convention(thin) (@owned Foo?) -> @out @sil_weak Foo? {

0 commit comments

Comments
 (0)