Skip to content

Commit 59af451

Browse files
authored
Merge pull request #67308 from apple/egorzhdan/5.9-foundation-linker-errors
🍒[cxx-interop] Import CF_OPTIONS types such as `Foundation.NSTextCheckingType` correctly
2 parents 74c223f + 8ef0ed5 commit 59af451

File tree

5 files changed

+36
-0
lines changed

5 files changed

+36
-0
lines changed

lib/ClangImporter/CFTypeInfo.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ CFPointeeInfo
5353
CFPointeeInfo::classifyTypedef(const clang::TypedefNameDecl *typedefDecl) {
5454
clang::QualType type = typedefDecl->getUnderlyingType();
5555

56+
if (auto elaborated = type->getAs<clang::ElaboratedType>())
57+
type = elaborated->desugar();
58+
5659
if (auto subTypedef = type->getAs<clang::TypedefType>()) {
5760
if (classifyTypedef(subTypedef->getDecl()))
5861
return forTypedef(subTypedef->getDecl());
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#define __CF_OPTIONS_ATTRIBUTES __attribute__((flag_enum,enum_extensibility(open)))
2+
#if (__cplusplus)
3+
#define CF_OPTIONS(_type, _name) __attribute__((availability(swift,unavailable))) _type _name; enum __CF_OPTIONS_ATTRIBUTES : _name
4+
#else
5+
#define CF_OPTIONS(_type, _name) enum __CF_OPTIONS_ATTRIBUTES _name : _type _name; enum _name : _type
6+
#endif
7+
8+
typedef CF_OPTIONS(unsigned int, NSTextCheckingType) {
9+
NSTextCheckingTypeOrthography = 1ULL << 0,
10+
NSTextCheckingTypeSpelling = 1ULL << 1,
11+
// ...
12+
};
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import NSTextCheckingResult
2+
3+
public func foo() -> NSTextCheckingType {
4+
return .orthography
5+
}

test/Interop/Cxx/objc-correctness/Inputs/module.modulemap

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,8 @@ module OSObject {
2424
requires objc
2525
requires cplusplus
2626
}
27+
28+
module NSTextCheckingResult {
29+
header "NSTextCheckingResult.h"
30+
requires objc
31+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend %S/Inputs/SwiftTextCheckingResult.swift -I %S/Inputs -module-name SwiftTextCheckingResult -enable-objc-interop -emit-module -emit-module-path %t/SwiftTextCheckingResult.swiftmodule
3+
// RUN: %target-typecheck-verify-swift -verify-ignore-unknown -I %t -I %S/Inputs -module-name SwiftTest -enable-objc-interop -enable-experimental-cxx-interop
4+
5+
// REQUIRES: objc_interop
6+
7+
import SwiftTextCheckingResult
8+
9+
let _ = foo()
10+
11+
// CHECK: @"$sSy10FoundationE20replacingOccurrences2of4with7options5rangeSSqd___qd_0_So22NSStringCompareOptionsVSnySS5IndexVGSgtSyRd__SyRd_0_r0_lF"

0 commit comments

Comments
 (0)