Skip to content

[MoveChecker] Fix visitor return. #72360

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/SILOptimizer/Mandatory/MoveOnlyUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ struct SimpleTemporaryAllocStackElimVisitor
state.setFinalUser(op);

// We found an instruction that we did not understand.
return true;
return false;
}
};

Expand Down
69 changes: 69 additions & 0 deletions test/SILOptimizer/moveonly_generics_complex.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// RUN: %target-swift-frontend \
// RUN: -emit-sil -verify \
// RUN: %s \
// RUN: -enable-experimental-feature BuiltinModule \
// RUN: -enable-experimental-feature NoncopyableGenerics \
// RUN: -sil-verify-all

// REQUIRES: asserts

import Builtin

@frozen
enum MyLittleLayout<T : ~Copyable> {
@_transparent
static var size: Int {
return Int(Builtin.sizeof(T.self))
}
@_transparent
static var stride: Int {
return Int(Builtin.strideof(T.self))
}
}

@frozen
enum MyLittleResult<Success : ~Copyable, Failure : Error> : ~Copyable {
case success(Success)
case failure(Failure)
}

@usableFromInline
@_alwaysEmitIntoClient
@inline(__always)
func _rethrowsViaClosure<R : ~Copyable>(_ fn: () throws -> R) rethrows -> R {
return try fn()
}

func _withUnprotectedUnsafeTemporaryAllocation<T: ~Copyable, R: ~Copyable>(
of type: T.Type,
capacity: Int,
alignment: Int,
_ body: (Builtin.RawPointer) throws -> R
) rethrows -> R {
let result: MyLittleResult<R, Error>
#if $BuiltinUnprotectedStackAlloc
let stackAddress = Builtin.unprotectedStackAlloc(
capacity._builtinWordValue,
MyLittleLayout<T>.stride._builtinWordValue,
alignment._builtinWordValue
)
#else
let stackAddress = Builtin.stackAlloc(
capacity._builtinWordValue,
MyLittleLayout<T>.stride._builtinWordValue,
alignment._builtinWordValue
)
#endif
do {
result = .success(try body(stackAddress))
Builtin.stackDealloc(stackAddress)
} catch {
result = .failure(error)
Builtin.stackDealloc(stackAddress)
}
switch consume result {
// FIXME: This shouldn't be diagnosed. But it's better than miscompiling.
case .success(let success): return success // expected-error{{cannot partially consume 'unknown'}}
case .failure(let error): return try _rethrowsViaClosure { throw error }
}
}