Skip to content

Commit 197b164

Browse files
Merge pull request #72272 from nate-chandler/noncopyable-bugs/20240312/2
[ConsumeAddrChecker] Check inout_aliasable arguments.
2 parents d4c347c + 862ee47 commit 197b164

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

lib/SILOptimizer/Mandatory/ConsumeOperatorCopyableAddressesChecker.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2466,7 +2466,8 @@ class ConsumeOperatorCopyableAddressesCheckerPass
24662466
if (arg->getType().isAddress() &&
24672467
(arg->hasConvention(SILArgumentConvention::Indirect_In) ||
24682468
arg->hasConvention(SILArgumentConvention::Indirect_In_Guaranteed) ||
2469-
arg->hasConvention(SILArgumentConvention::Indirect_Inout)))
2469+
arg->hasConvention(SILArgumentConvention::Indirect_Inout) ||
2470+
arg->hasConvention(SILArgumentConvention::Indirect_InoutAliasable)))
24702471
addressesToCheck.insert(arg);
24712472
}
24722473

test/SILOptimizer/consume_operator_kills_copyable_addressonly_vars.swift

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,13 +254,12 @@ extension DeferTestProtocol {
254254
print("123")
255255
}
256256

257-
// We do not support moving within a defer right now.
258257
mutating func deferTestFail1() {
259258
let selfType = type(of: self)
260259
let _ = (consume self)
261260
defer {
262261
self = selfType.getP()
263-
let _ = (consume self) // expected-error {{'consume' applied to value that the compiler does not support}}
262+
let _ = (consume self)
264263
}
265264
print("123")
266265
}
@@ -714,3 +713,11 @@ func inoutAndUseTest<T>(_ x: T) {
714713
useValueAndInOut(&y, consume y) // expected-note {{used here}}
715714
// expected-note @-1 {{consumed here}}
716715
}
716+
717+
@_silgen_name("consumeInoutAliasable")
718+
func consumeInoutAliasable<T>(_ x: inout T, other: T) {
719+
{
720+
_ = consume x
721+
x = other
722+
}()
723+
}

test/SILOptimizer/consume_operator_kills_copyable_loadable_vars.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,12 +314,11 @@ extension KlassWrapper {
314314
print("123")
315315
}
316316

317-
// We do not support moving within a defer right now.
318317
mutating func deferTestFail1() {
319318
let _ = (consume self)
320319
defer {
321320
self = KlassWrapper(k: Klass())
322-
let _ = (consume self) // expected-error {{'consume' applied to value that the compiler does not support}}
321+
let _ = (consume self)
323322
}
324323
print("123")
325324
}

0 commit comments

Comments
 (0)