[cfe-commits] r95863 - in /cfe/trunk: include/clang/AST/Attr.h lib/AST/AttrImpl.cpp lib/Frontend/PCHReaderDecl.cpp lib/Sema/SemaDeclAttr.cpp

Ted Kremenek kremenek at apple.com
Wed Feb 10 23:31:47 PST 2010


Author: kremenek
Date: Thu Feb 11 01:31:47 2010
New Revision: 95863

URL: http://llvm.org/viewvc/llvm-project?rev=95863&view=rev
Log:
Use the allocator associated with ASTContext to allocate the args
array associated with NonNullAttr.  This fixes yet another leak when
ASTContext uses a BumpPtrAllocator.

Fixes: <rdar://problem/7637150>

Modified:
    cfe/trunk/include/clang/AST/Attr.h
    cfe/trunk/lib/AST/AttrImpl.cpp
    cfe/trunk/lib/Frontend/PCHReaderDecl.cpp
    cfe/trunk/lib/Sema/SemaDeclAttr.cpp

Modified: cfe/trunk/include/clang/AST/Attr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Attr.h?rev=95863&r1=95862&r2=95863&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Attr.h (original)
+++ cfe/trunk/include/clang/AST/Attr.h Thu Feb 11 01:31:47 2010
@@ -361,19 +361,9 @@
   unsigned* ArgNums;
   unsigned Size;
 public:
-  NonNullAttr(unsigned* arg_nums = 0, unsigned size = 0) : Attr(NonNull),
-    ArgNums(0), Size(0) {
+  NonNullAttr(ASTContext &C, unsigned* arg_nums = 0, unsigned size = 0);
 
-    if (size == 0) return;
-    assert(arg_nums);
-    ArgNums = new unsigned[size];
-    Size = size;
-    memcpy(ArgNums, arg_nums, sizeof(*ArgNums)*size);
-  }
-
-  virtual ~NonNullAttr() {
-    delete [] ArgNums;
-  }
+  virtual void Destroy(ASTContext &C);
 
   typedef const unsigned *iterator;
   iterator begin() const { return ArgNums; }

Modified: cfe/trunk/lib/AST/AttrImpl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/AttrImpl.cpp?rev=95863&r1=95862&r2=95863&view=diff

==============================================================================
--- cfe/trunk/lib/AST/AttrImpl.cpp (original)
+++ cfe/trunk/lib/AST/AttrImpl.cpp Thu Feb 11 01:31:47 2010
@@ -50,6 +50,22 @@
   ReplaceString(C, type);
 }
 
+NonNullAttr::NonNullAttr(ASTContext &C, unsigned* arg_nums, unsigned size)
+  : Attr(NonNull), ArgNums(0), Size(0) {  
+  if (size == 0)
+    return;
+  assert(arg_nums);
+  ArgNums = new (C) unsigned[size];
+  Size = size;
+  memcpy(ArgNums, arg_nums, sizeof(*ArgNums)*size);
+}
+
+void NonNullAttr::Destroy(ASTContext &C) {
+  if (ArgNums)
+    C.Deallocate(ArgNums);
+  Attr::Destroy(C);
+}
+
 #define DEF_SIMPLE_ATTR_CLONE(ATTR)                                     \
   Attr *ATTR##Attr::clone(ASTContext &C) const {                        \
     return ::new (C) ATTR##Attr;                                        \
@@ -132,7 +148,7 @@
 }
 
 Attr *NonNullAttr::clone(ASTContext &C) const {
-  return ::new (C) NonNullAttr(ArgNums, Size);
+  return ::new (C) NonNullAttr(C, ArgNums, Size);
 }
 
 Attr *FormatAttr::clone(ASTContext &C) const {

Modified: cfe/trunk/lib/Frontend/PCHReaderDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHReaderDecl.cpp?rev=95863&r1=95862&r2=95863&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/PCHReaderDecl.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHReaderDecl.cpp Thu Feb 11 01:31:47 2010
@@ -532,7 +532,7 @@
       llvm::SmallVector<unsigned, 16> ArgNums;
       ArgNums.insert(ArgNums.end(), &Record[Idx], &Record[Idx] + Size);
       Idx += Size;
-      New = ::new (*Context) NonNullAttr(ArgNums.data(), Size);
+      New = ::new (*Context) NonNullAttr(*Context, ArgNums.data(), Size);
       break;
     }
 

Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=95863&r1=95862&r2=95863&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Thu Feb 11 01:31:47 2010
@@ -307,7 +307,7 @@
   unsigned* start = &NonNullArgs[0];
   unsigned size = NonNullArgs.size();
   std::sort(start, start + size);
-  d->addAttr(::new (S.Context) NonNullAttr(start, size));
+  d->addAttr(::new (S.Context) NonNullAttr(S.Context, start, size));
 }
 
 static void HandleAliasAttr(Decl *d, const AttributeList &Attr, Sema &S) {





More information about the cfe-commits mailing list