Skip to content

Commit 94b06b4

Browse files
Merge pull request swiftlang#71787 from nate-chandler/noncopyable-bugs/20240221/1
[IRGen] Lower release_value_addr of noncopyable to deinit call.
2 parents fe88a00 + 274e7c9 commit 94b06b4

File tree

2 files changed

+62
-10
lines changed

2 files changed

+62
-10
lines changed

lib/IRGen/IRGenSIL.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5095,6 +5095,9 @@ void IRGenSILFunction::visitReleaseValueAddrInst(
50955095
Address addr = getLoweredAddress(operandValue);
50965096
SILType addrTy = operandValue->getType();
50975097
SILType objectT = addrTy.getObjectType();
5098+
if (tryEmitDestroyUsingDeinit(*this, addr, addrTy)) {
5099+
return;
5100+
}
50985101
llvm::Type *llvmType = addr.getAddress()->getType();
50995102
const TypeInfo &addrTI = getTypeInfo(addrTy);
51005103
auto atomicity = i->isAtomic() ? Atomicity::Atomic : Atomicity::NonAtomic;
Lines changed: 59 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,55 @@
1-
// RUN: %target-swift-emit-irgen \
1+
// RUN: %target-swift-emit-irgen \
22
// RUN: -enable-experimental-feature NoncopyableGenerics \
3-
// RUN: %s \
4-
// RUN: | \
3+
// RUN: -disable-type-layout \
4+
// RUN: %s \
5+
// RUN: | \
56
// RUN: %FileCheck %s
67

8+
// Check that UMA_Large.deinit is called directly from FIFO_Large.deinit,
9+
// rather than through an outlined release function.
10+
// CHECK-LABEL: define{{.*}} void @"$s21moveonly_enum_deinits10FIFO_LargeVfD"
11+
// CHECK: call{{.*}} void @"$s21moveonly_enum_deinits9UMA_LargeVfD"
12+
// CHECK: }
13+
public struct FIFO_Large<T>: ~Copyable {
14+
public var uma: UMA_Large<T>
15+
public var i1: Int
16+
public var i2: Int
17+
18+
deinit {
19+
something(self)
20+
}
21+
}
22+
23+
public struct UMA_Large<T>: ~Copyable {
24+
public let umbp: UnsafeMutableBufferPointer<T>
25+
public var allocd: [Bool] = []
26+
deinit {
27+
something(self)
28+
}
29+
}
30+
31+
// Check that UMA_Small.deinit is called directly from FIFO_Small.deinit,
32+
// rather than through an outlined release function.
33+
// CHECK-LABEL: define{{.*}} void @"$s21moveonly_enum_deinits10FIFO_SmallVfD"
34+
// CHECK: call{{.*}} void @"$s21moveonly_enum_deinits9UMA_SmallVfD"
35+
// CHECK: }
36+
public struct FIFO_Small<T>: ~Copyable {
37+
public var uma: UMA_Small<T>
38+
public var i1: Int
39+
public var i2: Int
40+
41+
deinit {
42+
something(self)
43+
}
44+
}
45+
46+
public struct UMA_Small<T>: ~Copyable {
47+
public var allocd: [Bool] = []
48+
deinit {
49+
something(self)
50+
}
51+
}
52+
753
// CHECK-LABEL: define{{.*}} void @"$s21moveonly_enum_deinits4ListOwxx"(
854
// CHECK-SAME: ptr noalias %object,
955
// CHECK-SAME: ptr %List)
@@ -17,13 +63,16 @@
1763
// CHECK: ret void
1864
// CHECK: }
1965

20-
struct Box<T : ~Copyable> : ~Copyable {
21-
public init(_ l: consuming T) {}
22-
23-
deinit {}
66+
public struct Box<T : ~Copyable> : ~Copyable {
67+
public init(_ l: consuming T) {}
68+
69+
deinit {}
2470
}
2571

26-
enum List: ~Copyable {
27-
case end
28-
case more(Int, Box<List>)
72+
public enum List: ~Copyable {
73+
case end
74+
case more(Int, Box<List>)
2975
}
76+
77+
@_silgen_name("something")
78+
func something<T : ~Copyable>(_ t: borrowing T)

0 commit comments

Comments
 (0)