Skip to content

Commit a4162c5

Browse files
committed
[ClangImporter] Don't put forward-declared structs in the lookup table.
Otherwise, the lookup table for "CGColor" has two entries, because of this: typedef struct CGColor *CGColorRef; and that interferes with our ability to import things as members of "CGColor" (as opposed to "CGColorRef"), which affects the fix-its we generate when you try to use the non-member form. This isn't necessarily the best long-term solution (as noted in the FIXME) but it is expedient and won't break any current users. More rdar://problem/26347297
1 parent 2fa3da4 commit a4162c5

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

lib/ClangImporter/ClangImporter.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,24 @@ void ClangImporter::Implementation::addEntryToLookupTable(
775775
// Determine whether this declaration is suppressed in Swift.
776776
if (shouldSuppressDeclImport(named)) return;
777777

778+
// Leave incomplete struct/enum/union types out of the table; Swift only
779+
// handles pointers to them.
780+
// FIXME: At some point we probably want to be importing incomplete types,
781+
// so that pointers to different incomplete types themselves have distinct
782+
// types. At that time it will be necessary to make the decision of whether
783+
// or not to import an incomplete type declaration based on whether it's
784+
// actually the struct backing a CF type:
785+
//
786+
// typedef struct CGColor *CGColorRef;
787+
//
788+
// The best way to do this is probably to change CFDatabase.def to include
789+
// struct names when relevant, not just pointer names. That way we can check
790+
// both CFDatabase.def and the objc_bridge attribute and cover all our bases.
791+
if (auto *tagDecl = dyn_cast<clang::TagDecl>(named)) {
792+
if (!tagDecl->getDefinition())
793+
return;
794+
}
795+
778796
// If we have a name to import as, add this entry to the table.
779797
if (auto importedName = importFullName(named, None, &clangSema)) {
780798
table.addEntry(importedName.Imported, named, importedName.EffectiveContext);

test/IDE/Inputs/custom-modules/ImportAsMemberC.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
typedef const void *CFTypeRef __attribute__((objc_bridge(id)));
22

3-
typedef const struct __attribute__((objc_bridge(id))) __CCPowerSupply *CCPowerSupplyRef;
3+
typedef const struct __attribute__((objc_bridge(id))) CCPowerSupply *CCPowerSupplyRef;
44
typedef const struct __attribute__((objc_bridge(id))) __CCRefrigerator *CCRefrigeratorRef;
55
typedef struct __CCRefrigerator *CCMutableRefrigeratorRef;
66

test/IDE/dump_swift_lookup_tables_objc.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@
4444
// CHECK-NEXT: TU: SNSomeProtocol
4545
// CHECK: UIActionSheet:
4646
// CHECK-NEXT: TU: UIActionSheet
47-
// CHECK-NEXT: __CCItem:
48-
// CHECK-NEXT: TU: __CCItem
4947
// CHECK-NEXT: __swift:
5048
// CHECK-NEXT: TU: __swift
5149
// CHECK-NEXT: accessibilityFloat:

0 commit comments

Comments
 (0)