Skip to content

Commit 10a1c04

Browse files
authored
Merge pull request #20603 from brentdax/swift-5.0-branch-asan
[5.0] Fix lookupDirect() use-after-scope bugs
2 parents c74abe0 + 4a40a6e commit 10a1c04

File tree

4 files changed

+6
-8
lines changed

4 files changed

+6
-8
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7048,7 +7048,7 @@ void SwiftDeclConverter::importInheritedConstructors(
70487048

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

7051-
auto inheritConstructors = [&](ArrayRef<ValueDecl *> members,
7051+
auto inheritConstructors = [&](TinyPtrVector<ValueDecl *> members,
70527052
Optional<CtorInitializerKind> kind) {
70537053
const auto &languageVersion =
70547054
Impl.SwiftContext.LangOpts.EffectiveLanguageVersion;

lib/SILOptimizer/Utils/CastOptimizer.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -354,17 +354,15 @@ SILInstruction *CastOptimizer::optimizeBridgedSwiftToObjCCast(
354354

355355
auto *NTD = Source.getNominalOrBoundGenericNominal();
356356
assert(NTD);
357-
SmallVector<ValueDecl *, 4> FoundMembers;
358-
ArrayRef<ValueDecl *> Members;
359-
Members = NTD->lookupDirect(M.getASTContext().Id_bridgeToObjectiveC);
357+
auto Members = NTD->lookupDirect(M.getASTContext().Id_bridgeToObjectiveC);
360358
if (Members.empty()) {
359+
SmallVector<ValueDecl *, 4> FoundMembers;
361360
if (NTD->getDeclContext()->lookupQualified(
362361
NTD, M.getASTContext().Id_bridgeToObjectiveC,
363362
NLOptions::NL_ProtocolMembers, FoundMembers)) {
364-
Members = FoundMembers;
365363
// Returned members are starting with the most specialized ones.
366364
// Thus, the first element is what we are looking for.
367-
Members = Members.take_front(1);
365+
Members.push_back(FoundMembers.front());
368366
}
369367
}
370368

lib/Sema/CSDiag.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7089,7 +7089,7 @@ bool FailureDiagnosis::visitObjectLiteralExpr(ObjectLiteralExpr *E) {
70897089
return false;
70907090
DeclName constrName = TC.getObjectLiteralConstructorName(E);
70917091
assert(constrName);
7092-
ArrayRef<ValueDecl *> constrs = protocol->lookupDirect(constrName);
7092+
auto constrs = protocol->lookupDirect(constrName);
70937093
if (constrs.size() != 1 || !isa<ConstructorDecl>(constrs.front()))
70947094
return false;
70957095
auto *constr = cast<ConstructorDecl>(constrs.front());

lib/Sema/CSGen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1323,7 +1323,7 @@ namespace {
13231323
// use the right labels before forming the call to the initializer.
13241324
DeclName constrName = tc.getObjectLiteralConstructorName(expr);
13251325
assert(constrName);
1326-
ArrayRef<ValueDecl *> constrs = protocol->lookupDirect(constrName);
1326+
auto constrs = protocol->lookupDirect(constrName);
13271327
if (constrs.size() != 1 || !isa<ConstructorDecl>(constrs.front())) {
13281328
tc.diagnose(protocol, diag::object_literal_broken_proto);
13291329
return nullptr;

0 commit comments

Comments
 (0)