Skip to content

Commit 1b856e1

Browse files
authored
Merge pull request swiftlang#84040 from Xazax-hun/func-ptr-is-not-fragile
[cxx-interop] Do not consider function types fragile
2 parents 3cc52dc + ff6679d commit 1b856e1

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

lib/Sema/TypeCheckAccess.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "swift/Basic/Assertions.h"
3434
#include "clang/AST/DeclCXX.h"
3535
#include "clang/AST/DeclObjC.h"
36+
#include "clang/AST/Type.h"
3637

3738
using namespace swift;
3839

@@ -1947,6 +1948,15 @@ bool isFragileClangType(clang::QualType type) {
19471948
// Builtin clang types are compatible with library evolution.
19481949
if (underlyingTypePtr->isBuiltinType())
19491950
return false;
1951+
if (const auto *ft = dyn_cast<clang::FunctionType>(underlyingTypePtr)) {
1952+
if (const auto *fpt =
1953+
dyn_cast<clang::FunctionProtoType>(underlyingTypePtr)) {
1954+
for (auto paramTy : fpt->getParamTypes())
1955+
if (isFragileClangType(paramTy))
1956+
return true;
1957+
}
1958+
return isFragileClangType(ft->getReturnType());
1959+
}
19501960
// Pointers to non-fragile types are non-fragile.
19511961
if (underlyingTypePtr->isPointerType())
19521962
return isFragileClangType(underlyingTypePtr->getPointeeType());

test/Interop/Cxx/library-evolution/allow-c-in-cxx-mode-in-evolving-libraries.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ struct CStruct {
3939
}
4040
#endif
4141

42+
typedef void (*my_sighandler_t)(int);
43+
typedef void (*my_other_cb)(CxxStruct);
44+
4245
//--- test.swift
4346

4447
import CxxModule
@@ -55,3 +58,9 @@ public func useCxxEnum(_ x: CxxEnum) { // expected-error {{cannot use enum 'CxxE
5558
// expected-error@+1 {{cannot use struct 'CxxStruct' here; C++ types from imported module 'CxxModule' do not support library evolution}}
5659
public func usesCxxStruct(_ x: CxxStruct) {
5760
}
61+
62+
public func usesTypeAliasToFuncPtr(_ x: my_sighandler_t) {
63+
}
64+
65+
public func usesTypeAliasToFuncPtr2(_ x: my_other_cb) { // expected-error {{cannot use type alias 'my_other_cb' here; C++ types from imported module 'CxxModule' do not support library evolution}}
66+
}

0 commit comments

Comments
 (0)