From 5cc16a9d89d98c67882aeb3baa3c7813c71b4594 Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Tue, 20 Aug 2013 04:22:09 +0000 Subject: Add an error check for a typo I accidentally made in a td file that caused an assert to fire. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@188742 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/TableGen/TGParser.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'lib/TableGen') diff --git a/lib/TableGen/TGParser.cpp b/lib/TableGen/TGParser.cpp index 965cd00..daac574 100644 --- a/lib/TableGen/TGParser.cpp +++ b/lib/TableGen/TGParser.cpp @@ -2496,6 +2496,9 @@ bool TGParser::ParseDefm(MultiClass *CurMultiClass) { if (Lex.getCode() != tgtok::comma) break; Lex.Lex(); // eat ','. + if (Lex.getCode() != tgtok::Id) + return TokError("expected identifier"); + SubClassLoc = Lex.getLoc(); // A defm can inherit from regular classes (non-multiclass) as -- cgit v1.1 From 8f4397799f9eebdc149754c539619ccbed578b90 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Thu, 31 Oct 2013 04:07:41 +0000 Subject: Fix most memory leaks in tablegen. Found by the valgrind bot. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@193736 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/TableGen/Record.cpp | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) (limited to 'lib/TableGen') diff --git a/lib/TableGen/Record.cpp b/lib/TableGen/Record.cpp index 9ad2053..431f4aa 100644 --- a/lib/TableGen/Record.cpp +++ b/lib/TableGen/Record.cpp @@ -557,9 +557,23 @@ Init *BitsInit::resolveReferences(Record &R, const RecordVal *RV) const { return const_cast(this); } +namespace { + template + class Pool : public T { + public: + ~Pool(); + }; + template + Pool::~Pool() { + for (typename T::iterator I = this->begin(), E = this->end(); I != E; ++I) { + typename T::value_type &Item = *I; + delete Item.second; + } + } +} + IntInit *IntInit::get(int64_t V) { - typedef DenseMap Pool; - static Pool ThePool; + static Pool > ThePool; IntInit *&I = ThePool[V]; if (!I) I = new IntInit(V); @@ -586,8 +600,7 @@ IntInit::convertInitializerBitRange(const std::vector &Bits) const { void StringInit::anchor() { } StringInit *StringInit::get(StringRef V) { - typedef StringMap Pool; - static Pool ThePool; + static Pool > ThePool; StringInit *&I = ThePool[V]; if (!I) I = new StringInit(V); @@ -726,9 +739,7 @@ Init *OpInit::getBit(unsigned Bit) const { UnOpInit *UnOpInit::get(UnaryOp opc, Init *lhs, RecTy *Type) { typedef std::pair, RecTy *> Key; - - typedef DenseMap Pool; - static Pool ThePool; + static Pool > ThePool; Key TheKey(std::make_pair(std::make_pair(opc, lhs), Type)); @@ -873,8 +884,7 @@ BinOpInit *BinOpInit::get(BinaryOp opc, Init *lhs, RecTy * > Key; - typedef DenseMap Pool; - static Pool ThePool; + static Pool > ThePool; Key TheKey(std::make_pair(std::make_pair(std::make_pair(opc, lhs), rhs), Type)); @@ -1298,8 +1308,7 @@ VarInit *VarInit::get(const std::string &VN, RecTy *T) { VarInit *VarInit::get(Init *VN, RecTy *T) { typedef std::pair Key; - typedef DenseMap Pool; - static Pool ThePool; + static Pool > ThePool; Key TheKey(std::make_pair(T, VN)); -- cgit v1.1