Skip to content

[ClangImporter] Fix (lack of) name importing for ObjC ivars #40114

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/ClangImporter/ImportName.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1672,6 +1672,12 @@ ImportedName NameImporter::importNameImpl(const clang::NamedDecl *D,

// Spcial case: unnamed/anonymous fields.
if (auto field = dyn_cast<clang::FieldDecl>(D)) {
static_assert((clang::Decl::lastField - clang::Decl::firstField) == 2,
"update logic for new FieldDecl subclasses");
if (isa<clang::ObjCIvarDecl>(D) || isa<clang::ObjCAtDefsFieldDecl>(D))
// These are not ordinary fields and are not imported into Swift.
return result;

if (field->isAnonymousStructOrUnion() || field->getDeclName().isEmpty()) {
// Generate a field name for anonymous fields, this will be used in
// order to be able to expose the indirect fields injected from there
Expand Down
5 changes: 5 additions & 0 deletions lib/ClangImporter/SwiftLookupTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1860,6 +1860,11 @@ SwiftNameLookupExtension::hashExtension(llvm::hash_code code) const {
void importer::addEntryToLookupTable(SwiftLookupTable &table,
clang::NamedDecl *named,
NameImporter &nameImporter) {
clang::PrettyStackTraceDecl trace(
named, named->getLocation(),
nameImporter.getClangContext().getSourceManager(),
"while adding SwiftName lookup table entries for clang declaration");

// Determine whether this declaration is suppressed in Swift.
if (shouldSuppressDeclImport(named))
return;
Expand Down
5 changes: 4 additions & 1 deletion test/ClangImporter/Inputs/sdk-bridging-header.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

@class NSArray;

@interface MyPredicate : NSObject
@interface MyPredicate : NSObject {
int kind : 2; // Should not cause crash in PCH processing (rdar://85173321)
}

+ (nonnull MyPredicate *)truePredicate;
+ (nonnull MyPredicate *)not;
+ (nonnull MyPredicate *)and:(nonnull NSArray *)subpredicates;
Expand Down