Skip to content

[5.0] Fix lookupDirect() use-after-scope bugs #20603

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
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
2 changes: 1 addition & 1 deletion lib/ClangImporter/ImportDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7048,7 +7048,7 @@ void SwiftDeclConverter::importInheritedConstructors(

auto curObjCClass = cast<clang::ObjCInterfaceDecl>(classDecl->getClangDecl());

auto inheritConstructors = [&](ArrayRef<ValueDecl *> members,
auto inheritConstructors = [&](TinyPtrVector<ValueDecl *> members,
Optional<CtorInitializerKind> kind) {
const auto &languageVersion =
Impl.SwiftContext.LangOpts.EffectiveLanguageVersion;
Expand Down
8 changes: 3 additions & 5 deletions lib/SILOptimizer/Utils/CastOptimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,17 +354,15 @@ SILInstruction *CastOptimizer::optimizeBridgedSwiftToObjCCast(

auto *NTD = Source.getNominalOrBoundGenericNominal();
assert(NTD);
SmallVector<ValueDecl *, 4> FoundMembers;
ArrayRef<ValueDecl *> Members;
Members = NTD->lookupDirect(M.getASTContext().Id_bridgeToObjectiveC);
auto Members = NTD->lookupDirect(M.getASTContext().Id_bridgeToObjectiveC);
if (Members.empty()) {
SmallVector<ValueDecl *, 4> FoundMembers;
if (NTD->getDeclContext()->lookupQualified(
NTD, M.getASTContext().Id_bridgeToObjectiveC,
NLOptions::NL_ProtocolMembers, FoundMembers)) {
Members = FoundMembers;
// Returned members are starting with the most specialized ones.
// Thus, the first element is what we are looking for.
Members = Members.take_front(1);
Members.push_back(FoundMembers.front());
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Sema/CSDiag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7089,7 +7089,7 @@ bool FailureDiagnosis::visitObjectLiteralExpr(ObjectLiteralExpr *E) {
return false;
DeclName constrName = TC.getObjectLiteralConstructorName(E);
assert(constrName);
ArrayRef<ValueDecl *> constrs = protocol->lookupDirect(constrName);
auto constrs = protocol->lookupDirect(constrName);
if (constrs.size() != 1 || !isa<ConstructorDecl>(constrs.front()))
return false;
auto *constr = cast<ConstructorDecl>(constrs.front());
Expand Down
2 changes: 1 addition & 1 deletion lib/Sema/CSGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1323,7 +1323,7 @@ namespace {
// use the right labels before forming the call to the initializer.
DeclName constrName = tc.getObjectLiteralConstructorName(expr);
assert(constrName);
ArrayRef<ValueDecl *> constrs = protocol->lookupDirect(constrName);
auto constrs = protocol->lookupDirect(constrName);
if (constrs.size() != 1 || !isa<ConstructorDecl>(constrs.front())) {
tc.diagnose(protocol, diag::object_literal_broken_proto);
return nullptr;
Expand Down