diff --git a/lib/ClangImporter/ImportDecl.cpp b/lib/ClangImporter/ImportDecl.cpp index c76f7e8ddf868..62b6d6a908855 100644 --- a/lib/ClangImporter/ImportDecl.cpp +++ b/lib/ClangImporter/ImportDecl.cpp @@ -1133,14 +1133,18 @@ createValueConstructor(ClangImporter::Implementation &Impl, // To keep DI happy, initialize stored properties before computed. for (unsigned pass = 0; pass < 2; pass++) { + unsigned paramPos = 0; + for (unsigned i = 0, e = members.size(); i < e; i++) { auto var = members[i]; if (var->hasClangNode() && isa(var->getClangDecl())) continue; - if (var->hasStorage() == (pass != 0)) + if (var->hasStorage() == (pass != 0)) { + paramPos++; continue; + } // Construct left-hand side. Expr *lhs = new (context) DeclRefExpr(selfDecl, DeclNameLoc(), @@ -1149,12 +1153,14 @@ createValueConstructor(ClangImporter::Implementation &Impl, /*Implicit=*/true); // Construct right-hand side. - auto rhs = new (context) DeclRefExpr(valueParameters[i], DeclNameLoc(), + auto rhs = new (context) DeclRefExpr(valueParameters[paramPos], + DeclNameLoc(), /*Implicit=*/true); // Add assignment. stmts.push_back(new (context) AssignExpr(lhs, SourceLoc(), rhs, /*Implicit=*/true)); + paramPos++; } } diff --git a/test/ClangImporter/Inputs/custom-modules/IndirectFields.h b/test/ClangImporter/Inputs/custom-modules/IndirectFields.h new file mode 100644 index 0000000000000..f6d7cf6fbd7ce --- /dev/null +++ b/test/ClangImporter/Inputs/custom-modules/IndirectFields.h @@ -0,0 +1,16 @@ +struct StructWithIndirectField { + union { + int a; + int b; + }; + int c; + int d : 3; /* Imported as a computed property */ +}; + +union UnionWithIndirectField { + struct { + int a; + int b; + }; + int c; +}; diff --git a/test/ClangImporter/Inputs/custom-modules/module.map b/test/ClangImporter/Inputs/custom-modules/module.map index b11318236557c..e08f8d616dff5 100644 --- a/test/ClangImporter/Inputs/custom-modules/module.map +++ b/test/ClangImporter/Inputs/custom-modules/module.map @@ -150,3 +150,7 @@ module MacrosRedefA { module MacrosRedefB { header "MacrosRedefB.h" } + +module IndirectFields { + header "IndirectFields.h" +} diff --git a/test/ClangImporter/indirect_fields.swift b/test/ClangImporter/indirect_fields.swift new file mode 100644 index 0000000000000..fb9d42c33ce90 --- /dev/null +++ b/test/ClangImporter/indirect_fields.swift @@ -0,0 +1,19 @@ +// RUN: %target-swift-frontend -typecheck -sdk "" -I %t -I %S/Inputs/custom-modules %s -verify + +import IndirectFields + +func build_struct(a: Int32, c: Int32, d: Int32) -> StructWithIndirectField { + return StructWithIndirectField(__Anonymous_field0: .init(a: a), c: c, d: d) +} + +func build_struct(b: Int32, c: Int32, d: Int32) -> StructWithIndirectField { + return StructWithIndirectField(__Anonymous_field0: .init(b: b), c: c, d: d) +} + +func build_union(a: Int32, b: Int32) -> UnionWithIndirectField { + return UnionWithIndirectField(__Anonymous_field0: .init(a: a, b: b)) +} + +func build_union(c: Int32) -> UnionWithIndirectField { + return UnionWithIndirectField(c: c) +}