Skip to content

Commit aac2051

Browse files
Merge pull request #72257 from nate-chandler/noncopyable-bugs/20240312/1
[ConsumeAddrChecker] Check in_guaranteed arguments.
2 parents 6e9e9c4 + cb3417e commit aac2051

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

lib/SILOptimizer/Mandatory/ConsumeOperatorCopyableAddressesChecker.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2465,6 +2465,7 @@ class ConsumeOperatorCopyableAddressesCheckerPass
24652465
for (auto *arg : fn->front().getSILFunctionArguments()) {
24662466
if (arg->getType().isAddress() &&
24672467
(arg->hasConvention(SILArgumentConvention::Indirect_In) ||
2468+
arg->hasConvention(SILArgumentConvention::Indirect_In_Guaranteed) ||
24682469
arg->hasConvention(SILArgumentConvention::Indirect_Inout)))
24692470
addressesToCheck.insert(arg);
24702471
}

test/SILOptimizer/consume_operator_kills_copyable_addressonly_lets.swift

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public func conditionalBadConsumingUseLoop2<T>(_ x: T) {
147147

148148
// This is ok, no uses after.
149149
public func simpleMoveOfParameter<T>(_ x: T) -> () {
150-
let _ = consume x // expected-error {{'consume' applied to value that the compiler does not support}}
150+
let _ = consume x
151151
}
152152

153153
public func simpleMoveOfOwnedParameter<T>(_ x: __owned T) -> () {
@@ -202,6 +202,26 @@ public func errorLoopMoveOfParameterNonConsume<T>(_ x: __owned T) -> () { // exp
202202
}
203203
}
204204

205+
func consumeConsuming<T>(_ k: consuming T) {
206+
_ = consume k
207+
}
208+
209+
func consumeBorrowing<T>(_ k: borrowing T) { // expected-error{{'k' is borrowed and cannot be consumed}}
210+
_ = consume k // expected-note{{consumed here}}
211+
}
212+
213+
func consumeOwned<T>(_ k: __owned T) {
214+
_ = consume k
215+
}
216+
217+
func consumeShared<T>(_ k: __shared T) {
218+
_ = consume k
219+
}
220+
221+
func consumeBare<T>(_ k: T) {
222+
_ = consume k
223+
}
224+
205225
////////////////////////
206226
// Pattern Match Lets //
207227
////////////////////////

0 commit comments

Comments
 (0)