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:
@@ -322,15 +322,15 @@ void CompilerInstance::performParse() {
|
||||
|
||||
if (!Invocation.getParseOnly()) {
|
||||
// Type-check each top-level input besides the main source file.
|
||||
auto InputSourceFiles = MainModule->getFiles().slice(0, BufferIDs.size());
|
||||
for (auto File : InputSourceFiles)
|
||||
for (auto File : MainModule->getFiles())
|
||||
if (auto SF = dyn_cast<SourceFile>(File))
|
||||
if (PrimaryBufferID == NO_SUCH_BUFFER ||
|
||||
(SF->getBufferID().hasValue() &&
|
||||
SF->getBufferID().getValue() == PrimaryBufferID))
|
||||
performTypeChecking(*SF, PersistentState.getTopLevelContext());
|
||||
|
||||
// If there were no source files, we should still record known protocols.
|
||||
// Even if there were no source files, we should still record known
|
||||
// protocols.
|
||||
if (Context->getStdlibModule())
|
||||
Context->recordKnownProtocols(Context->getStdlibModule());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user