mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Fix a use-after-free caused by creating DerivedFileUnit on the fly
Sema was creating DerivedFileUnit on the fly, while something else is iterating over FileUnits in the module. The fix is to create DerivedFileUnit in advance. This change immediately uncovered a lot of code that assumed that the module consists of a single FileUnit at certain conditions. This patch also fixes that code (SourceKit patch is separate, not sending it). The test change is because now operator == on NSObjects is correctly recognised as coming from a system module. rdar://16153700, rdar://16227621, possibly rdar://16049613 Swift SVN r14692
This commit is contained in:
@@ -44,10 +44,10 @@ void DerivedConformance::_insertOperatorDecl(NominalTypeDecl *scope,
|
||||
// Find the module.
|
||||
auto &C = scope->getASTContext();
|
||||
auto mod = scope->getModuleContext();
|
||||
|
||||
|
||||
// Add it to the module in a DerivedFileUnit.
|
||||
mod->addFile(*new (C) DerivedFileUnit(*mod, cast<FuncDecl>(member)));
|
||||
|
||||
mod->getDerivedFileUnit().addDerivedDecl(cast<FuncDecl>(member));
|
||||
|
||||
// Add it as a derived global decl to the nominal type.
|
||||
auto oldDerived = scope->getDerivedGlobalDecls();
|
||||
auto oldSize = oldDerived.size();
|
||||
|
||||
Reference in New Issue
Block a user