[cfe-commits] r95930 - in /cfe/trunk: include/clang/AST/ExprObjC.h lib/AST/Expr.cpp lib/Frontend/RewriteObjC.cpp lib/Sema/SemaExpr.cpp lib/Sema/SemaExprObjC.cpp
Ted Kremenek
kremenek at apple.com
Thu Feb 11 14:41:21 PST 2010
Author: kremenek
Date: Thu Feb 11 16:41:21 2010
New Revision: 95930
URL: http://llvm.org/viewvc/llvm-project?rev=95930&view=rev
Log:
Allocate the SubExprs array in ObjCMessageExpr using the allocator associated with ASTContext. This fixes yet another leak (<rdar://problem/7639260>).
Modified:
cfe/trunk/include/clang/AST/ExprObjC.h
cfe/trunk/lib/AST/Expr.cpp
cfe/trunk/lib/Frontend/RewriteObjC.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/lib/Sema/SemaExprObjC.cpp
Modified: cfe/trunk/include/clang/AST/ExprObjC.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ExprObjC.h?rev=95930&r1=95929&r2=95930&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/ExprObjC.h (original)
+++ cfe/trunk/include/clang/AST/ExprObjC.h Thu Feb 11 16:41:21 2010
@@ -367,7 +367,7 @@
public:
/// This constructor is used to represent class messages where the
/// ObjCInterfaceDecl* of the receiver is not known.
- ObjCMessageExpr(IdentifierInfo *clsName, Selector selInfo,
+ ObjCMessageExpr(ASTContext &C, IdentifierInfo *clsName, Selector selInfo,
QualType retType, ObjCMethodDecl *methDecl,
SourceLocation LBrac, SourceLocation RBrac,
Expr **ArgExprs, unsigned NumArgs);
@@ -375,13 +375,13 @@
/// This constructor is used to represent class messages where the
/// ObjCInterfaceDecl* of the receiver is known.
// FIXME: clsName should be typed to ObjCInterfaceType
- ObjCMessageExpr(ObjCInterfaceDecl *cls, Selector selInfo,
+ ObjCMessageExpr(ASTContext &C, ObjCInterfaceDecl *cls, Selector selInfo,
QualType retType, ObjCMethodDecl *methDecl,
SourceLocation LBrac, SourceLocation RBrac,
Expr **ArgExprs, unsigned NumArgs);
// constructor for instance messages.
- ObjCMessageExpr(Expr *receiver, Selector selInfo,
+ ObjCMessageExpr(ASTContext &C, Expr *receiver, Selector selInfo,
QualType retType, ObjCMethodDecl *methDecl,
SourceLocation LBrac, SourceLocation RBrac,
Expr **ArgExprs, unsigned NumArgs);
@@ -389,9 +389,7 @@
explicit ObjCMessageExpr(EmptyShell Empty)
: Expr(ObjCMessageExprClass, Empty), SubExprs(0), NumArgs(0) {}
- ~ObjCMessageExpr() {
- delete [] SubExprs;
- }
+ virtual void DoDestroy(ASTContext &C);
/// getReceiver - Returns the receiver of the message expression.
/// This can be NULL if the message is for class methods. For
Modified: cfe/trunk/lib/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=95930&r1=95929&r2=95930&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Thu Feb 11 16:41:21 2010
@@ -2057,14 +2057,15 @@
}
// constructor for instance messages.
-ObjCMessageExpr::ObjCMessageExpr(Expr *receiver, Selector selInfo,
- QualType retType, ObjCMethodDecl *mproto,
- SourceLocation LBrac, SourceLocation RBrac,
- Expr **ArgExprs, unsigned nargs)
+ObjCMessageExpr::ObjCMessageExpr(ASTContext &C, Expr *receiver,
+ Selector selInfo,
+ QualType retType, ObjCMethodDecl *mproto,
+ SourceLocation LBrac, SourceLocation RBrac,
+ Expr **ArgExprs, unsigned nargs)
: Expr(ObjCMessageExprClass, retType, false, false), SelName(selInfo),
MethodProto(mproto) {
NumArgs = nargs;
- SubExprs = new Stmt*[NumArgs+1];
+ SubExprs = new (C) Stmt*[NumArgs+1];
SubExprs[RECEIVER] = receiver;
if (NumArgs) {
for (unsigned i = 0; i != NumArgs; ++i)
@@ -2076,14 +2077,15 @@
// constructor for class messages.
// FIXME: clsName should be typed to ObjCInterfaceType
-ObjCMessageExpr::ObjCMessageExpr(IdentifierInfo *clsName, Selector selInfo,
- QualType retType, ObjCMethodDecl *mproto,
- SourceLocation LBrac, SourceLocation RBrac,
- Expr **ArgExprs, unsigned nargs)
+ObjCMessageExpr::ObjCMessageExpr(ASTContext &C, IdentifierInfo *clsName,
+ Selector selInfo, QualType retType,
+ ObjCMethodDecl *mproto,
+ SourceLocation LBrac, SourceLocation RBrac,
+ Expr **ArgExprs, unsigned nargs)
: Expr(ObjCMessageExprClass, retType, false, false), SelName(selInfo),
MethodProto(mproto) {
NumArgs = nargs;
- SubExprs = new Stmt*[NumArgs+1];
+ SubExprs = new (C) Stmt*[NumArgs+1];
SubExprs[RECEIVER] = (Expr*) ((uintptr_t) clsName | IsClsMethDeclUnknown);
if (NumArgs) {
for (unsigned i = 0; i != NumArgs; ++i)
@@ -2094,14 +2096,15 @@
}
// constructor for class messages.
-ObjCMessageExpr::ObjCMessageExpr(ObjCInterfaceDecl *cls, Selector selInfo,
- QualType retType, ObjCMethodDecl *mproto,
- SourceLocation LBrac, SourceLocation RBrac,
- Expr **ArgExprs, unsigned nargs)
+ObjCMessageExpr::ObjCMessageExpr(ASTContext &C, ObjCInterfaceDecl *cls,
+ Selector selInfo, QualType retType,
+ ObjCMethodDecl *mproto, SourceLocation LBrac,
+ SourceLocation RBrac, Expr **ArgExprs,
+ unsigned nargs)
: Expr(ObjCMessageExprClass, retType, false, false), SelName(selInfo),
MethodProto(mproto) {
NumArgs = nargs;
- SubExprs = new Stmt*[NumArgs+1];
+ SubExprs = new (C) Stmt*[NumArgs+1];
SubExprs[RECEIVER] = (Expr*) ((uintptr_t) cls | IsClsMethDeclKnown);
if (NumArgs) {
for (unsigned i = 0; i != NumArgs; ++i)
@@ -2136,6 +2139,13 @@
SubExprs[RECEIVER] = (Expr*)((uintptr_t)CI.first | IsClsMethDeclKnown);
}
+void ObjCMessageExpr::DoDestroy(ASTContext &C) {
+ DestroyChildren(C);
+ if (SubExprs)
+ C.Deallocate(SubExprs);
+ this->~ObjCMessageExpr();
+ C.Deallocate((void*) this);
+}
bool ChooseExpr::isConditionTrue(ASTContext &C) const {
return getCond()->EvaluateAsInt(C) != 0;
Modified: cfe/trunk/lib/Frontend/RewriteObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/RewriteObjC.cpp?rev=95930&r1=95929&r2=95930&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/RewriteObjC.cpp (original)
+++ cfe/trunk/lib/Frontend/RewriteObjC.cpp Thu Feb 11 16:41:21 2010
@@ -1159,7 +1159,7 @@
// This allows us to handle chain/nested property getters.
Receiver = PropGetters[PRE];
}
- MsgExpr = new (Context) ObjCMessageExpr(dyn_cast<Expr>(Receiver),
+ MsgExpr = new (Context) ObjCMessageExpr(*Context, dyn_cast<Expr>(Receiver),
PDecl->getSetterName(), PDecl->getType(),
PDecl->getSetterMethodDecl(),
SourceLocation(), SourceLocation(),
@@ -1188,7 +1188,7 @@
// This allows us to handle chain/nested property getters.
Receiver = PropGetters[PRE];
}
- MsgExpr = new (Context) ObjCMessageExpr(dyn_cast<Expr>(Receiver),
+ MsgExpr = new (Context) ObjCMessageExpr(*Context, dyn_cast<Expr>(Receiver),
PDecl->getGetterName(), PDecl->getType(),
PDecl->getGetterMethodDecl(),
SourceLocation(), SourceLocation(),
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=95930&r1=95929&r2=95930&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Thu Feb 11 16:41:21 2010
@@ -3043,7 +3043,7 @@
if (DiagnoseUseOfDecl(OMD, MemberLoc))
return ExprError();
- return Owned(new (Context) ObjCMessageExpr(BaseExpr, Sel,
+ return Owned(new (Context) ObjCMessageExpr(Context, BaseExpr, Sel,
OMD->getResultType(),
OMD, OpLoc, MemberLoc,
NULL, 0));
Modified: cfe/trunk/lib/Sema/SemaExprObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprObjC.cpp?rev=95930&r1=95929&r2=95930&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprObjC.cpp Thu Feb 11 16:41:21 2010
@@ -470,11 +470,13 @@
// now, we simply pass the "super" identifier through (which isn't consistent
// with instance methods.
if (isSuper)
- return new (Context) ObjCMessageExpr(receiverName, Sel, returnType, Method,
- lbrac, rbrac, ArgExprs, NumArgs);
+ return new (Context) ObjCMessageExpr(Context, receiverName, Sel, returnType,
+ Method, lbrac, rbrac, ArgExprs,
+ NumArgs);
else
- return new (Context) ObjCMessageExpr(ClassDecl, Sel, returnType, Method,
- lbrac, rbrac, ArgExprs, NumArgs);
+ return new (Context) ObjCMessageExpr(Context, ClassDecl, Sel, returnType,
+ Method, lbrac, rbrac, ArgExprs,
+ NumArgs);
}
// ActOnInstanceMessage - used for both unary and keyword messages.
@@ -521,8 +523,9 @@
return true;
returnType = returnType.getNonReferenceType();
- return new (Context) ObjCMessageExpr(RExpr, Sel, returnType, Method, lbrac,
- rbrac, ArgExprs, NumArgs);
+ return new (Context) ObjCMessageExpr(Context, RExpr, Sel, returnType,
+ Method, lbrac, rbrac,
+ ArgExprs, NumArgs);
}
// Handle messages to id.
@@ -536,8 +539,9 @@
lbrac, rbrac, returnType))
return true;
returnType = returnType.getNonReferenceType();
- return new (Context) ObjCMessageExpr(RExpr, Sel, returnType, Method, lbrac,
- rbrac, ArgExprs, NumArgs);
+ return new (Context) ObjCMessageExpr(Context, RExpr, Sel, returnType,
+ Method, lbrac, rbrac,
+ ArgExprs, NumArgs);
}
// Handle messages to Class.
@@ -582,8 +586,9 @@
lbrac, rbrac, returnType))
return true;
returnType = returnType.getNonReferenceType();
- return new (Context) ObjCMessageExpr(RExpr, Sel, returnType, Method, lbrac,
- rbrac, ArgExprs, NumArgs);
+ return new (Context) ObjCMessageExpr(Context, RExpr, Sel, returnType,
+ Method, lbrac, rbrac,
+ ArgExprs, NumArgs);
}
ObjCMethodDecl *Method = 0;
@@ -665,7 +670,7 @@
lbrac, rbrac, returnType))
return true;
returnType = returnType.getNonReferenceType();
- return new (Context) ObjCMessageExpr(RExpr, Sel, returnType, Method, lbrac,
- rbrac, ArgExprs, NumArgs);
+ return new (Context) ObjCMessageExpr(Context, RExpr, Sel, returnType, Method,
+ lbrac, rbrac, ArgExprs, NumArgs);
}
More information about the cfe-commits
mailing list