Skip to content

Commit 891dc3e

Browse files
authored
Merge pull request #6513 from modocache/sr-2394-returns-twice-unavailable
2 parents 6378079 + a9439bb commit 891dc3e

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2955,6 +2955,18 @@ namespace {
29552955
if (decl->isVariadic()) {
29562956
Impl.markUnavailable(result, "Variadic function is unavailable");
29572957
}
2958+
2959+
if (decl->hasAttr<clang::ReturnsTwiceAttr>()) {
2960+
// The Clang 'returns_twice' attribute is used for functions like
2961+
// 'vfork' or 'setjmp'. Because these functions may return control flow
2962+
// of a Swift program to an arbitrary point, Swift's guarantees of
2963+
// definitive initialization of variables cannot be upheld. As a result,
2964+
// functions like these cannot be used in Swift.
2965+
Impl.markUnavailable(
2966+
result,
2967+
"Functions that may return more than one time (annotated with the "
2968+
"'returns_twice' attribute) are unavailable in Swift");
2969+
}
29582970
}
29592971

29602972
Decl *VisitCXXMethodDecl(const clang::CXXMethodDecl *decl) {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// RUN: %target-swift-frontend -typecheck -verify %s
2+
3+
#if os(OSX) || os(iOS) || os(watchOS) || os(tvOS)
4+
import Darwin
5+
typealias JumpBuffer = Int32
6+
#else
7+
import Glibc
8+
typealias JumpBuffer = jmp_buf
9+
#endif
10+
11+
func test_unavailable_returns_twice_function() {
12+
var x: JumpBuffer
13+
_ = setjmp(&x) // expected-error {{'setjmp' is unavailable: Functions that may return more than one time (annotated with the 'returns_twice' attribute) are unavailable in Swift}}
14+
}
15+

0 commit comments

Comments
 (0)