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:
@@ -26,6 +26,7 @@
|
||||
#include "llvm/ADT/ArrayRef.h"
|
||||
#include "llvm/ADT/DenseSet.h"
|
||||
#include "llvm/ADT/SmallSet.h"
|
||||
#include "llvm/ADT/SmallVector.h"
|
||||
#include "llvm/ADT/StringMap.h"
|
||||
#include "llvm/ADT/TinyPtrVector.h"
|
||||
#include "llvm/Support/ErrorHandling.h"
|
||||
@@ -42,6 +43,7 @@ namespace swift {
|
||||
enum class DeclKind : uint8_t;
|
||||
class ExtensionDecl;
|
||||
class DebuggerClient;
|
||||
class DerivedFileUnit;
|
||||
class FileUnit;
|
||||
class FuncDecl;
|
||||
class InfixOperatorDecl;
|
||||
@@ -172,7 +174,7 @@ private:
|
||||
// FIXME: Do we really need to bloat all modules with this?
|
||||
DebuggerClient *DebugClient = nullptr;
|
||||
|
||||
TinyPtrVector<FileUnit *> Files;
|
||||
SmallVector<FileUnit *, 2> Files;
|
||||
|
||||
Module(Identifier name, ASTContext &ctx);
|
||||
public:
|
||||
@@ -198,6 +200,8 @@ public:
|
||||
/// dealing with.
|
||||
FileUnit &getMainFile(FileUnitKind expectedKind) const;
|
||||
|
||||
DerivedFileUnit &getDerivedFileUnit() const;
|
||||
|
||||
DebuggerClient *getDebugClient() const { return DebugClient; }
|
||||
void setDebugClient(DebuggerClient *R) {
|
||||
assert(!DebugClient && "Debugger client already set");
|
||||
@@ -555,13 +559,16 @@ public:
|
||||
/// A container for a module-level definition derived as part of an implicit
|
||||
/// protocol conformance.
|
||||
class DerivedFileUnit final : public FileUnit {
|
||||
FuncDecl *const DerivedDecl;
|
||||
|
||||
TinyPtrVector<FuncDecl *> DerivedDecls;
|
||||
|
||||
public:
|
||||
DerivedFileUnit(Module &M, FuncDecl *derivedDecl)
|
||||
: FileUnit(FileUnitKind::Derived, M), DerivedDecl(derivedDecl) {}
|
||||
~DerivedFileUnit() {}
|
||||
|
||||
DerivedFileUnit(Module &M);
|
||||
~DerivedFileUnit() = default;
|
||||
|
||||
void addDerivedDecl(FuncDecl *FD) {
|
||||
DerivedDecls.push_back(FD);
|
||||
}
|
||||
|
||||
void lookupValue(Module::AccessPathTy accessPath, Identifier name,
|
||||
NLKind lookupKind,
|
||||
SmallVectorImpl<ValueDecl*> &result) const override;
|
||||
|
||||
Reference in New Issue
Block a user