Skip to content

Commit 52dfb1a

Browse files
committed
Fix issue where mutable syth methods were not in the lookup table
1 parent 781a90c commit 52dfb1a

File tree

1 file changed

+35
-12
lines changed

1 file changed

+35
-12
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3334,7 +3334,7 @@ namespace {
33343334
// Track whether this record contains fields we can't reference in Swift
33353335
// as stored properties.
33363336
bool hasUnreferenceableStorage = false;
3337-
3337+
33383338
// Track whether this record contains fields that can't be zero-
33393339
// initialized.
33403340
bool hasZeroInitializableStorage = true;
@@ -3444,11 +3444,12 @@ namespace {
34443444
// that differ this way so we can disambiguate later
34453445
for (auto m : decl->decls()) {
34463446
if (auto method = dyn_cast<clang::CXXMethodDecl>(m)) {
3447-
if(method->getDeclName().isIdentifier()) {
3448-
if(Impl.cxxMethods.find(method->getName()) == Impl.cxxMethods.end()) {
3447+
if (method->getDeclName().isIdentifier()) {
3448+
if (Impl.cxxMethods.find(method->getName()) ==
3449+
Impl.cxxMethods.end()) {
34493450
Impl.cxxMethods[method->getName()] = {};
34503451
}
3451-
if(method->isConst()) {
3452+
if (method->isConst()) {
34523453
// Add to const set
34533454
Impl.cxxMethods[method->getName()].first.insert(method);
34543455
} else {
@@ -3478,8 +3479,8 @@ namespace {
34783479

34793480
if (auto field = dyn_cast<clang::FieldDecl>(nd)) {
34803481
// Non-nullable pointers can't be zero-initialized.
3481-
if (auto nullability = field->getType()
3482-
->getNullability(Impl.getClangASTContext())) {
3482+
if (auto nullability =
3483+
field->getType()->getNullability(Impl.getClangASTContext())) {
34833484
if (*nullability == clang::NullabilityKind::NonNull)
34843485
hasZeroInitializableStorage = false;
34853486
}
@@ -3522,6 +3523,18 @@ namespace {
35223523
}
35233524

35243525
if (auto MD = dyn_cast<FuncDecl>(member)) {
3526+
3527+
// When 2 CXXMethods diff by "constness" alone we differentiate them
3528+
// by changing the name of one. That changed method needs to be added
3529+
// to the lookup table since it cannot be found lazily.
3530+
if (auto cxxMethod = dyn_cast<clang::CXXMethodDecl>(m)) {
3531+
if (cxxMethod->getDeclName().isIdentifier()) {
3532+
auto &mutableFuncPtrs = Impl.cxxMethods[cxxMethod->getName()].second;
3533+
if(mutableFuncPtrs.contains(cxxMethod)) {
3534+
result->addMemberToLookupTable(member);
3535+
}
3536+
}
3537+
}
35253538
methods.push_back(MD);
35263539
continue;
35273540
}
@@ -3596,10 +3609,10 @@ namespace {
35963609
//
35973610
// If we can completely represent the struct in SIL, leave the body
35983611
// implicit, otherwise synthesize one to call property setters.
3599-
auto valueCtor = createValueConstructor(
3600-
Impl, result, members,
3601-
/*want param names*/true,
3602-
/*want body*/hasUnreferenceableStorage);
3612+
auto valueCtor =
3613+
createValueConstructor(Impl, result, members,
3614+
/*want param names*/ true,
3615+
/*want body*/ hasUnreferenceableStorage);
36033616
if (!hasUnreferenceableStorage)
36043617
valueCtor->setIsMemberwiseInitializer();
36053618

@@ -3630,14 +3643,24 @@ namespace {
36303643
continue;
36313644

36323645
auto getterAndSetter = subscriptInfo.second;
3633-
auto subscript = makeSubscript(getterAndSetter.first,
3634-
getterAndSetter.second);
3646+
auto subscript =
3647+
makeSubscript(getterAndSetter.first, getterAndSetter.second);
36353648
// Also add subscripts directly because they won't be found from the
36363649
// clang decl.
36373650
result->addMember(subscript);
36383651
}
36393652
}
36403653

3654+
//
3655+
// for (auto &cxxMethod : Impl.cxxMethods) {
3656+
// for (auto &mutFuncPtr : cxxMethod.getSecond().second) {
3657+
// Decl *member =
3658+
// Impl.importDecl(mutFuncPtr->getUnderlyingDecl(),
3659+
// getActiveSwiftVersion());
3660+
// if(member)
3661+
// result->addMemberToLookupTable(member);
3662+
// }
3663+
// }
36413664
result->setMemberLoader(&Impl, 0);
36423665
return result;
36433666
}

0 commit comments

Comments
 (0)