Skip to content

Commit 0547323

Browse files
Merge pull request #72360 from nate-chandler/noncopyable-bugs/20240315/1
[MoveChecker] Fix visitor return.
2 parents 2d3b251 + 73531d4 commit 0547323

File tree

2 files changed

+70
-1
lines changed

2 files changed

+70
-1
lines changed

lib/SILOptimizer/Mandatory/MoveOnlyUtils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ struct SimpleTemporaryAllocStackElimVisitor
547547
state.setFinalUser(op);
548548

549549
// We found an instruction that we did not understand.
550-
return true;
550+
return false;
551551
}
552552
};
553553

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// RUN: %target-swift-frontend \
2+
// RUN: -emit-sil -verify \
3+
// RUN: %s \
4+
// RUN: -enable-experimental-feature BuiltinModule \
5+
// RUN: -enable-experimental-feature NoncopyableGenerics \
6+
// RUN: -sil-verify-all
7+
8+
// REQUIRES: asserts
9+
10+
import Builtin
11+
12+
@frozen
13+
enum MyLittleLayout<T : ~Copyable> {
14+
@_transparent
15+
static var size: Int {
16+
return Int(Builtin.sizeof(T.self))
17+
}
18+
@_transparent
19+
static var stride: Int {
20+
return Int(Builtin.strideof(T.self))
21+
}
22+
}
23+
24+
@frozen
25+
enum MyLittleResult<Success : ~Copyable, Failure : Error> : ~Copyable {
26+
case success(Success)
27+
case failure(Failure)
28+
}
29+
30+
@usableFromInline
31+
@_alwaysEmitIntoClient
32+
@inline(__always)
33+
func _rethrowsViaClosure<R : ~Copyable>(_ fn: () throws -> R) rethrows -> R {
34+
return try fn()
35+
}
36+
37+
func _withUnprotectedUnsafeTemporaryAllocation<T: ~Copyable, R: ~Copyable>(
38+
of type: T.Type,
39+
capacity: Int,
40+
alignment: Int,
41+
_ body: (Builtin.RawPointer) throws -> R
42+
) rethrows -> R {
43+
let result: MyLittleResult<R, Error>
44+
#if $BuiltinUnprotectedStackAlloc
45+
let stackAddress = Builtin.unprotectedStackAlloc(
46+
capacity._builtinWordValue,
47+
MyLittleLayout<T>.stride._builtinWordValue,
48+
alignment._builtinWordValue
49+
)
50+
#else
51+
let stackAddress = Builtin.stackAlloc(
52+
capacity._builtinWordValue,
53+
MyLittleLayout<T>.stride._builtinWordValue,
54+
alignment._builtinWordValue
55+
)
56+
#endif
57+
do {
58+
result = .success(try body(stackAddress))
59+
Builtin.stackDealloc(stackAddress)
60+
} catch {
61+
result = .failure(error)
62+
Builtin.stackDealloc(stackAddress)
63+
}
64+
switch consume result {
65+
// FIXME: This shouldn't be diagnosed. But it's better than miscompiling.
66+
case .success(let success): return success // expected-error{{cannot partially consume 'unknown'}}
67+
case .failure(let error): return try _rethrowsViaClosure { throw error }
68+
}
69+
}

0 commit comments

Comments
 (0)