Skip to content

Commit 3cd6a65

Browse files
authored
Merge pull request #34395 from compnerd/clang-importer
ClangImporter: support the MS anonymous structure extension
2 parents 0fb4080 + 4a89483 commit 3cd6a65

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1390,7 +1390,8 @@ createValueConstructor(ClangImporter::Implementation &Impl,
13901390
continue;
13911391

13921392
if (auto clangField = dyn_cast<clang::FieldDecl>(var->getClangDecl()))
1393-
if (clangField->isAnonymousStructOrUnion())
1393+
if (clangField->isAnonymousStructOrUnion() ||
1394+
clangField->getDeclName().isEmpty())
13941395
generateParamName = false;
13951396
}
13961397

@@ -2397,6 +2398,8 @@ namespace {
23972398
if (field->isAnonymousStructOrUnion()) {
23982399
IdStream << "__Anonymous_field" << field->getFieldIndex();
23992400
} else {
2401+
assert(!field->getDeclName().isEmpty() &&
2402+
"Microsoft anonymous struct extension?");
24002403
IdStream << field->getName();
24012404
}
24022405
ImportedName Result;
@@ -4011,7 +4014,7 @@ namespace {
40114014
Optional<ImportedName> correctSwiftName;
40124015
ImportedName importedName;
40134016

4014-
if (!decl->isAnonymousStructOrUnion()) {
4017+
if (!decl->isAnonymousStructOrUnion() && !decl->getDeclName().isEmpty()) {
40154018
importedName = importFullName(decl, correctSwiftName);
40164019
if (!importedName) {
40174020
return nullptr;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
typedef struct S {
3+
unsigned char uc;
4+
} S;
5+
6+
typedef struct T {
7+
S;
8+
} T;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// RUN: %target-swift-frontend -Xcc -fms-extensions -import-objc-header %S/Inputs/ctypes_msvc.h -typecheck -verify %s
2+
3+
_ = T().uc
4+
_ = T(S(uc: 0))

0 commit comments

Comments
 (0)