Skip to content

Commit 95cf518

Browse files
Xazax-hunGabor Horvath
authored andcommitted
[6.2][cxx-interop] Do not consider function types fragile
Explanationion: Function pointer types wee always considered fragile in C++ mode, this manifested as a regression when interfacing with glibc. Issues: rdar://159184118 Original PRs: swiftlang#84040 Risk: Low, this only removes a spurious error for library evolution. Testing: Added a compiler test. Reviewers: @egorzhdan
1 parent f15d600 commit 95cf518

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
@@ -32,6 +32,7 @@
3232
#include "swift/Basic/Assertions.h"
3333
#include "clang/AST/DeclCXX.h"
3434
#include "clang/AST/DeclObjC.h"
35+
#include "clang/AST/Type.h"
3536

3637
using namespace swift;
3738

@@ -1862,6 +1863,15 @@ bool isFragileClangType(clang::QualType type) {
18621863
// Builtin clang types are compatible with library evolution.
18631864
if (underlyingTypePtr->isBuiltinType())
18641865
return false;
1866+
if (const auto *ft = dyn_cast<clang::FunctionType>(underlyingTypePtr)) {
1867+
if (const auto *fpt =
1868+
dyn_cast<clang::FunctionProtoType>(underlyingTypePtr)) {
1869+
for (auto paramTy : fpt->getParamTypes())
1870+
if (isFragileClangType(paramTy))
1871+
return true;
1872+
}
1873+
return isFragileClangType(ft->getReturnType());
1874+
}
18651875
// Pointers to non-fragile types are non-fragile.
18661876
if (underlyingTypePtr->isPointerType())
18671877
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)