Skip to content

ClangImporter: support the MS anonymous structure extension #34395

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
Oct 23, 2020
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
7 changes: 5 additions & 2 deletions lib/ClangImporter/ImportDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1390,7 +1390,8 @@ createValueConstructor(ClangImporter::Implementation &Impl,
continue;

if (auto clangField = dyn_cast<clang::FieldDecl>(var->getClangDecl()))
if (clangField->isAnonymousStructOrUnion())
if (clangField->isAnonymousStructOrUnion() ||
clangField->getDeclName().isEmpty())
generateParamName = false;
}

Expand Down Expand Up @@ -2397,6 +2398,8 @@ namespace {
if (field->isAnonymousStructOrUnion()) {
IdStream << "__Anonymous_field" << field->getFieldIndex();
} else {
assert(!field->getDeclName().isEmpty() &&
"Microsoft anonymous struct extension?");
IdStream << field->getName();
}
ImportedName Result;
Expand Down Expand Up @@ -4011,7 +4014,7 @@ namespace {
Optional<ImportedName> correctSwiftName;
ImportedName importedName;

if (!decl->isAnonymousStructOrUnion()) {
if (!decl->isAnonymousStructOrUnion() && !decl->getDeclName().isEmpty()) {
importedName = importFullName(decl, correctSwiftName);
if (!importedName) {
return nullptr;
Expand Down
8 changes: 8 additions & 0 deletions test/ClangImporter/Inputs/ctypes_msvc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

typedef struct S {
unsigned char uc;
} S;

typedef struct T {
S;
} T;
4 changes: 4 additions & 0 deletions test/ClangImporter/ctypes_parse_msvc.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// RUN: %target-swift-frontend -Xcc -fms-extensions -import-objc-header %S/Inputs/ctypes_msvc.h -typecheck -verify %s

_ = T().uc
_ = T(S(uc: 0))