[cfe-commits] r168771 - in /cfe/trunk: include/clang/AST/ASTUnresolvedSet.h include/clang/AST/ASTVector.h include/clang/AST/DeclCXX.h include/clang/AST/Expr.h include/clang/AST/UnresolvedSet.h include/clang/Serialization/ASTReader.h include/clang/Serialization/ASTWriter.h lib/AST/DeclCXX.cpp lib/Serialization/ASTReader.cpp lib/Serialization/ASTReaderStmt.cpp lib/Serialization/ASTWriter.cpp
Argyrios Kyrtzidis
akyrtzi at gmail.com
Tue Nov 27 19:56:16 PST 2012
Author: akirtzidis
Date: Tue Nov 27 21:56:16 2012
New Revision: 168771
URL: http://llvm.org/viewvc/llvm-project?rev=168771&view=rev
Log:
Introduce ASTUnresolvedSet, an UnresolvedSet-like class, whose contents are
allocated using the allocator associated with an ASTContext.
Use this inside CXXRecordDecl::DefinitionData instead of an UnresolvedSet to
avoid a potential memory leak.
rdar://12761275
Added:
cfe/trunk/include/clang/AST/ASTUnresolvedSet.h
Modified:
cfe/trunk/include/clang/AST/ASTVector.h
cfe/trunk/include/clang/AST/DeclCXX.h
cfe/trunk/include/clang/AST/Expr.h
cfe/trunk/include/clang/AST/UnresolvedSet.h
cfe/trunk/include/clang/Serialization/ASTReader.h
cfe/trunk/include/clang/Serialization/ASTWriter.h
cfe/trunk/lib/AST/DeclCXX.cpp
cfe/trunk/lib/Serialization/ASTReader.cpp
cfe/trunk/lib/Serialization/ASTReaderStmt.cpp
cfe/trunk/lib/Serialization/ASTWriter.cpp
Added: cfe/trunk/include/clang/AST/ASTUnresolvedSet.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTUnresolvedSet.h?rev=168771&view=auto
==============================================================================
--- cfe/trunk/include/clang/AST/ASTUnresolvedSet.h (added)
+++ cfe/trunk/include/clang/AST/ASTUnresolvedSet.h Tue Nov 27 21:56:16 2012
@@ -0,0 +1,86 @@
+//===-- ASTUnresolvedSet.h - Unresolved sets of declarations ---*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file provides an UnresolvedSet-like class, whose contents are
+// allocated using the allocator associated with an ASTContext.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_AST_ASTUNRESOLVEDSET_H
+#define LLVM_CLANG_AST_ASTUNRESOLVEDSET_H
+
+#include "clang/AST/UnresolvedSet.h"
+#include "clang/AST/ASTVector.h"
+
+namespace clang {
+
+/// \brief An UnresolvedSet-like class which uses the ASTContext's allocator.
+class ASTUnresolvedSet {
+ typedef ASTVector<DeclAccessPair> DeclsTy;
+ DeclsTy Decls;
+
+ ASTUnresolvedSet(const ASTUnresolvedSet &) LLVM_DELETED_FUNCTION;
+ void operator=(const ASTUnresolvedSet &) LLVM_DELETED_FUNCTION;
+
+public:
+ ASTUnresolvedSet() {}
+ ASTUnresolvedSet(ASTContext &C, unsigned N) : Decls(C, N) {}
+
+ typedef UnresolvedSetIterator iterator;
+ typedef UnresolvedSetIterator const_iterator;
+
+ iterator begin() { return iterator(Decls.begin()); }
+ iterator end() { return iterator(Decls.end()); }
+
+ const_iterator begin() const { return const_iterator(Decls.begin()); }
+ const_iterator end() const { return const_iterator(Decls.end()); }
+
+ void addDecl(ASTContext &C, NamedDecl *D) {
+ addDecl(C, D, AS_none);
+ }
+
+ void addDecl(ASTContext &C, NamedDecl *D, AccessSpecifier AS) {
+ Decls.push_back(DeclAccessPair::make(D, AS), C);
+ }
+
+ /// Replaces the given declaration with the new one, once.
+ ///
+ /// \return true if the set changed
+ bool replace(const NamedDecl* Old, NamedDecl *New) {
+ for (DeclsTy::iterator I = Decls.begin(), E = Decls.end(); I != E; ++I)
+ if (I->getDecl() == Old)
+ return (I->setDecl(New), true);
+ return false;
+ }
+
+ void erase(unsigned I) {
+ Decls[I] = Decls.back();
+ Decls.pop_back();
+ }
+
+ void clear() { Decls.clear(); }
+
+ bool empty() const { return Decls.empty(); }
+ unsigned size() const { return Decls.size(); }
+
+ void reserve(ASTContext &C, unsigned N) {
+ Decls.reserve(C, N);
+ }
+
+ void append(ASTContext &C, iterator I, iterator E) {
+ Decls.append(C, I.ir, E.ir);
+ }
+
+ DeclAccessPair &operator[](unsigned I) { return Decls[I]; }
+ const DeclAccessPair &operator[](unsigned I) const { return Decls[I]; }
+};
+
+} // namespace clang
+
+#endif
Modified: cfe/trunk/include/clang/AST/ASTVector.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTVector.h?rev=168771&r1=168770&r2=168771&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/ASTVector.h (original)
+++ cfe/trunk/include/clang/AST/ASTVector.h Tue Nov 27 21:56:16 2012
@@ -59,7 +59,9 @@
public:
// Default ctor - Initialize to empty.
- explicit ASTVector(ASTContext &C, unsigned N = 0)
+ ASTVector() : Begin(NULL), End(NULL), Capacity(NULL) { }
+
+ ASTVector(ASTContext &C, unsigned N)
: Begin(NULL), End(NULL), Capacity(NULL) {
reserve(C, N);
}
Modified: cfe/trunk/include/clang/AST/DeclCXX.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclCXX.h?rev=168771&r1=168770&r2=168771&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclCXX.h (original)
+++ cfe/trunk/include/clang/AST/DeclCXX.h Tue Nov 27 21:56:16 2012
@@ -19,7 +19,7 @@
#include "clang/AST/ExprCXX.h"
#include "clang/AST/Decl.h"
#include "clang/AST/TypeLoc.h"
-#include "clang/AST/UnresolvedSet.h"
+#include "clang/AST/ASTUnresolvedSet.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/PointerIntPair.h"
#include "llvm/ADT/SmallPtrSet.h"
@@ -522,14 +522,14 @@
/// of this C++ class (but not its inherited conversion
/// functions). Each of the entries in this overload set is a
/// CXXConversionDecl.
- UnresolvedSet<4> Conversions;
+ ASTUnresolvedSet Conversions;
/// VisibleConversions - Overload set containing the conversion
/// functions of this C++ class and all those inherited conversion
/// functions that are visible in this class. Each of the entries
/// in this overload set is a CXXConversionDecl or a
/// FunctionTemplateDecl.
- UnresolvedSet<4> VisibleConversions;
+ ASTUnresolvedSet VisibleConversions;
/// Definition - The declaration which defines this record.
CXXRecordDecl *Definition;
Modified: cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=168771&r1=168770&r2=168771&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Tue Nov 27 21:56:16 2012
@@ -3580,8 +3580,8 @@
ArrayRef<Expr*> initExprs, SourceLocation rbraceloc);
/// \brief Build an empty initializer list.
- explicit InitListExpr(ASTContext &C, EmptyShell Empty)
- : Expr(InitListExprClass, Empty), InitExprs(C) { }
+ explicit InitListExpr(EmptyShell Empty)
+ : Expr(InitListExprClass, Empty) { }
unsigned getNumInits() const { return InitExprs.size(); }
Modified: cfe/trunk/include/clang/AST/UnresolvedSet.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/UnresolvedSet.h?rev=168771&r1=168770&r2=168771&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/UnresolvedSet.h (original)
+++ cfe/trunk/include/clang/AST/UnresolvedSet.h Tue Nov 27 21:56:16 2012
@@ -25,12 +25,13 @@
/// non-const iterator.
class UnresolvedSetIterator {
private:
- typedef SmallVectorImpl<DeclAccessPair> DeclsTy;
+ typedef llvm::MutableArrayRef<DeclAccessPair> DeclsTy;
typedef DeclsTy::iterator IteratorTy;
IteratorTy ir;
friend class UnresolvedSetImpl;
+ friend class ASTUnresolvedSet;
friend class OverloadExpr;
explicit UnresolvedSetIterator(DeclsTy::iterator ir) : ir(ir) {}
explicit UnresolvedSetIterator(DeclsTy::const_iterator ir) :
@@ -87,7 +88,7 @@
/// UnresolvedSet - A set of unresolved declarations.
class UnresolvedSetImpl {
- typedef UnresolvedSetIterator::DeclsTy DeclsTy;
+ typedef SmallVectorImpl<DeclAccessPair> DeclsTy;
// Don't allow direct construction, and only permit subclassing by
// UnresolvedSet.
Modified: cfe/trunk/include/clang/Serialization/ASTReader.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTReader.h?rev=168771&r1=168770&r2=168771&view=diff
==============================================================================
--- cfe/trunk/include/clang/Serialization/ASTReader.h (original)
+++ cfe/trunk/include/clang/Serialization/ASTReader.h Tue Nov 27 21:56:16 2012
@@ -85,6 +85,7 @@
struct HeaderFileInfo;
class VersionTuple;
class TargetOptions;
+class ASTUnresolvedSet;
/// \brief Abstract interface for callback invocations by the ASTReader.
///
@@ -1612,7 +1613,7 @@
unsigned &Idx);
/// \brief Read a UnresolvedSet structure.
- void ReadUnresolvedSet(ModuleFile &F, UnresolvedSetImpl &Set,
+ void ReadUnresolvedSet(ModuleFile &F, ASTUnresolvedSet &Set,
const RecordData &Record, unsigned &Idx);
/// \brief Read a C++ base specifier.
Modified: cfe/trunk/include/clang/Serialization/ASTWriter.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTWriter.h?rev=168771&r1=168770&r2=168771&view=diff
==============================================================================
--- cfe/trunk/include/clang/Serialization/ASTWriter.h (original)
+++ cfe/trunk/include/clang/Serialization/ASTWriter.h Tue Nov 27 21:56:16 2012
@@ -63,6 +63,7 @@
class SwitchCase;
class TargetInfo;
class VersionTuple;
+class ASTUnresolvedSet;
namespace SrcMgr { class SLocEntry; }
@@ -603,7 +604,7 @@
RecordDataImpl &Record);
/// \brief Emit a UnresolvedSet structure.
- void AddUnresolvedSet(const UnresolvedSetImpl &Set, RecordDataImpl &Record);
+ void AddUnresolvedSet(const ASTUnresolvedSet &Set, RecordDataImpl &Record);
/// \brief Emit a C++ base specifier.
void AddCXXBaseSpecifier(const CXXBaseSpecifier &Base,
Modified: cfe/trunk/lib/AST/DeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclCXX.cpp?rev=168771&r1=168770&r2=168771&view=diff
==============================================================================
--- cfe/trunk/lib/AST/DeclCXX.cpp (original)
+++ cfe/trunk/lib/AST/DeclCXX.cpp Tue Nov 27 21:56:16 2012
@@ -709,13 +709,13 @@
data().Conversions.replace(FunTmpl->getPreviousDecl(),
FunTmpl);
else
- data().Conversions.addDecl(FunTmpl);
+ data().Conversions.addDecl(getASTContext(), FunTmpl);
} else {
if (Conversion->getPreviousDecl())
data().Conversions.replace(Conversion->getPreviousDecl(),
Conversion);
else
- data().Conversions.addDecl(Conversion);
+ data().Conversions.addDecl(getASTContext(), Conversion);
}
}
@@ -935,7 +935,7 @@
if (UsingShadowDecl *Shadow = dyn_cast<UsingShadowDecl>(D))
if (Shadow->getDeclName().getNameKind()
== DeclarationName::CXXConversionFunctionName)
- data().Conversions.addDecl(Shadow, Shadow->getAccess());
+ data().Conversions.addDecl(getASTContext(), Shadow, Shadow->getAccess());
}
bool CXXRecordDecl::isCLike() const {
@@ -996,7 +996,7 @@
bool InVirtual,
AccessSpecifier Access,
const llvm::SmallPtrSet<CanQualType, 8> &ParentHiddenTypes,
- UnresolvedSetImpl &Output,
+ ASTUnresolvedSet &Output,
UnresolvedSetImpl &VOutput,
llvm::SmallPtrSet<NamedDecl*, 8> &HiddenVBaseCs) {
// The set of types which have conversions in this class or its
@@ -1032,7 +1032,7 @@
if (InVirtual)
VOutput.addDecl(I.getDecl(), IAccess);
else
- Output.addDecl(I.getDecl(), IAccess);
+ Output.addDecl(Context, I.getDecl(), IAccess);
}
}
}
@@ -1059,7 +1059,7 @@
/// bases. It might be worth special-casing that, really.
static void CollectVisibleConversions(ASTContext &Context,
CXXRecordDecl *Record,
- UnresolvedSetImpl &Output) {
+ ASTUnresolvedSet &Output) {
// The collection of all conversions in virtual bases that we've
// found. These will be added to the output as long as they don't
// appear in the hidden-conversions set.
@@ -1076,7 +1076,7 @@
// hidden-types set.
CXXRecordDecl::conversion_iterator ConvI = Record->conversion_begin();
CXXRecordDecl::conversion_iterator ConvE = Record->conversion_end();
- Output.append(ConvI, ConvE);
+ Output.append(Context, ConvI, ConvE);
for (; ConvI != ConvE; ++ConvI)
HiddenTypes.insert(GetConversionType(Context, ConvI.getDecl()));
@@ -1095,7 +1095,7 @@
for (UnresolvedSetIterator I = VBaseCs.begin(), E = VBaseCs.end();
I != E; ++I) {
if (!HiddenVBaseCs.count(cast<NamedDecl>(I.getDecl()->getCanonicalDecl())))
- Output.addDecl(I.getDecl(), I.getAccess());
+ Output.addDecl(Context, I.getDecl(), I.getAccess());
}
}
@@ -1127,7 +1127,7 @@
// with sufficiently large numbers of directly-declared conversions
// that asymptotic behavior matters.
- UnresolvedSetImpl &Convs = data().Conversions;
+ ASTUnresolvedSet &Convs = data().Conversions;
for (unsigned I = 0, E = Convs.size(); I != E; ++I) {
if (Convs[I].getDecl() == ConvDecl) {
Convs.erase(I);
@@ -1266,7 +1266,7 @@
for (UnresolvedSetIterator I = data().Conversions.begin(),
E = data().Conversions.end();
I != E; ++I)
- data().Conversions.setAccess(I, (*I)->getAccess());
+ I.setAccess((*I)->getAccess());
}
bool CXXRecordDecl::mayBeAbstract() const {
Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=168771&r1=168770&r2=168771&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Tue Nov 27 21:56:16 2012
@@ -6448,13 +6448,14 @@
}
/// \brief Read a UnresolvedSet structure.
-void ASTReader::ReadUnresolvedSet(ModuleFile &F, UnresolvedSetImpl &Set,
+void ASTReader::ReadUnresolvedSet(ModuleFile &F, ASTUnresolvedSet &Set,
const RecordData &Record, unsigned &Idx) {
unsigned NumDecls = Record[Idx++];
+ Set.reserve(Context, NumDecls);
while (NumDecls--) {
NamedDecl *D = ReadDeclAs<NamedDecl>(F, Record, Idx);
AccessSpecifier AS = (AccessSpecifier)Record[Idx++];
- Set.addDecl(D, AS);
+ Set.addDecl(Context, D, AS);
}
}
Modified: cfe/trunk/lib/Serialization/ASTReaderStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReaderStmt.cpp?rev=168771&r1=168770&r2=168771&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReaderStmt.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReaderStmt.cpp Tue Nov 27 21:56:16 2012
@@ -1868,7 +1868,7 @@
break;
case EXPR_INIT_LIST:
- S = new (Context) InitListExpr(getContext(), Empty);
+ S = new (Context) InitListExpr(Empty);
break;
case EXPR_DESIGNATED_INIT:
Modified: cfe/trunk/lib/Serialization/ASTWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriter.cpp?rev=168771&r1=168770&r2=168771&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTWriter.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriter.cpp Tue Nov 27 21:56:16 2012
@@ -4480,9 +4480,9 @@
void
-ASTWriter::AddUnresolvedSet(const UnresolvedSetImpl &Set, RecordDataImpl &Record) {
+ASTWriter::AddUnresolvedSet(const ASTUnresolvedSet &Set, RecordDataImpl &Record) {
Record.push_back(Set.size());
- for (UnresolvedSetImpl::const_iterator
+ for (ASTUnresolvedSet::const_iterator
I = Set.begin(), E = Set.end(); I != E; ++I) {
AddDeclRef(I.getDecl(), Record);
Record.push_back(I.getAccess());
More information about the cfe-commits
mailing list