mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
ClangImporter: fix crash when importing type containing bitfields.
Following PR #6531 there is a position mismatch in the final loop between the position of the member in the members arrays and the position in the valueParameters array. As a consequence, a structure containing indirect fields before a computed properties (like a bitfield) caused an invalid access in the valueParameters array resulting in a crash of the compiler. This patch maintains a separate position for accessing valueParameters. A non-regression test is also added. Signed-off-by: Florent Bruneau <florent.bruneau@intersec.com>
This commit is contained in:
@@ -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<clang::IndirectFieldDecl>(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++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user