[cfe-commits] r150733 - in /cfe/trunk: lib/StaticAnalyzer/Checkers/MallocChecker.cpp test/Analysis/malloc-annotations.c test/Analysis/malloc-plist.c test/Analysis/malloc.c

Anna Zaks ganna at apple.com
Thu Feb 16 14:26:13 PST 2012


Author: zaks
Date: Thu Feb 16 16:26:12 2012
New Revision: 150733

URL: http://llvm.org/viewvc/llvm-project?rev=150733&view=rev
Log:
[analyzer] Malloc Checker: Clean up bug naming:
 - Rename the category "Logic Error" -> "Memory Error".
 - Shorten all the messages.

Modified:
    cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
    cfe/trunk/test/Analysis/malloc-annotations.c
    cfe/trunk/test/Analysis/malloc-plist.c
    cfe/trunk/test/Analysis/malloc.c

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp?rev=150733&r1=150732&r2=150733&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp Thu Feb 16 16:26:12 2012
@@ -91,11 +91,10 @@
                                      eval::Assume,
                                      check::RegionChanges>
 {
-  mutable OwningPtr<BuiltinBug> BT_DoubleFree;
-  mutable OwningPtr<BuiltinBug> BT_Leak;
-  mutable OwningPtr<BuiltinBug> BT_UseFree;
-  mutable OwningPtr<BuiltinBug> BT_UseRelinquished;
-  mutable OwningPtr<BuiltinBug> BT_BadFree;
+  mutable OwningPtr<BugType> BT_DoubleFree;
+  mutable OwningPtr<BugType> BT_Leak;
+  mutable OwningPtr<BugType> BT_UseFree;
+  mutable OwningPtr<BugType> BT_BadFree;
   mutable IdentifierInfo *II_malloc, *II_free, *II_realloc, *II_calloc,
                          *II_valloc, *II_reallocf;
 
@@ -519,10 +518,9 @@
     if (ExplodedNode *N = C.generateSink()) {
       if (!BT_DoubleFree)
         BT_DoubleFree.reset(
-          new BuiltinBug("Double free",
-                         "Try to free a memory block that has been released"));
+          new BugType("Double free", "Memory Error"));
       BugReport *R = new BugReport(*BT_DoubleFree, 
-                                   BT_DoubleFree->getDescription(), N);
+                        "Attempt to free released memory", N);
       R->addRange(ArgExpr->getSourceRange());
       R->addVisitor(new MallocBugVisitor(Sym));
       C.EmitReport(R);
@@ -627,7 +625,7 @@
                                   SourceRange range) const {
   if (ExplodedNode *N = C.generateSink()) {
     if (!BT_BadFree)
-      BT_BadFree.reset(new BuiltinBug("Bad free"));
+      BT_BadFree.reset(new BugType("Bad free", "Memory Error"));
     
     SmallString<100> buf;
     llvm::raw_svector_ostream os(buf);
@@ -766,8 +764,7 @@
                                CheckerContext &C) const {
   assert(N);
   if (!BT_Leak) {
-    BT_Leak.reset(new BuiltinBug("Memory leak",
-        "Allocated memory never released. Potential memory leak."));
+    BT_Leak.reset(new BugType("Memory leak", "Memory Error"));
     // Leaks should not be reported if they are post-dominated by a sink:
     // (1) Sinks are higher importance bugs.
     // (2) NoReturnFunctionChecker uses sink nodes to represent paths ending
@@ -776,7 +773,8 @@
     BT_Leak->setSuppressOnSink(true);
   }
 
-  BugReport *R = new BugReport(*BT_Leak, BT_Leak->getDescription(), N);
+  BugReport *R = new BugReport(*BT_Leak,
+                  "Memory is never released; potential memory leak", N);
   R->addVisitor(new MallocBugVisitor(Sym));
   C.EmitReport(R);
 }
@@ -897,10 +895,10 @@
   if (RS && RS->isReleased()) {
     if (ExplodedNode *N = C.generateSink()) {
       if (!BT_UseFree)
-        BT_UseFree.reset(new BuiltinBug("Use of dynamically allocated memory "
-            "after it is freed."));
+        BT_UseFree.reset(new BugType("Use-after-free", "Memory Error"));
 
-      BugReport *R = new BugReport(*BT_UseFree, BT_UseFree->getDescription(),N);
+      BugReport *R = new BugReport(*BT_UseFree,
+                                   "Use of memory after it is freed",N);
       if (S)
         R->addRange(S->getSourceRange());
       R->addVisitor(new MallocBugVisitor(Sym));

Modified: cfe/trunk/test/Analysis/malloc-annotations.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/malloc-annotations.c?rev=150733&r1=150732&r2=150733&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/malloc-annotations.c (original)
+++ cfe/trunk/test/Analysis/malloc-annotations.c Thu Feb 16 16:26:12 2012
@@ -24,19 +24,19 @@
 
 void f1() {
   int *p = malloc(12);
-  return; // expected-warning{{Allocated memory never released. Potential memory leak.}}
+  return; // expected-warning{{Memory is never released; potential memory leak}}
 }
 
 void f2() {
   int *p = malloc(12);
   free(p);
-  free(p); // expected-warning{{Try to free a memory block that has been released}}
+  free(p); // expected-warning{{Attempt to free released memory}}
 }
 
 void f2_realloc_0() {
   int *p = malloc(12);
   realloc(p,0);
-  realloc(p,0); // expected-warning{{Try to free a memory block that has been released}}
+  realloc(p,0); // expected-warning{{Attempt to free released memory}}
 }
 
 void f2_realloc_1() {
@@ -52,16 +52,16 @@
 
 void n2af1() {
   int *p = my_malloc2(12);
-  return; // expected-warning{{Allocated memory never released. Potential memory leak.}}
+  return; // expected-warning{{Memory is never released; potential memory leak}}
 }
 
 void af1() {
   int *p = my_malloc(12);
-  return; // expected-warning{{Allocated memory never released. Potential memory leak.}}
+  return; // expected-warning{{Memory is never released; potential memory leak}}
 }
 
 void af1_b() {
-  int *p = my_malloc(12); // expected-warning{{Allocated memory never released. Potential memory leak.}}
+  int *p = my_malloc(12); // expected-warning{{Memory is never released; potential memory leak}}
 }
 
 void af1_c() {
@@ -92,25 +92,25 @@
 void af2() {
   int *p = my_malloc(12);
   my_free(p);
-  free(p); // expected-warning{{Try to free a memory block that has been released}}
+  free(p); // expected-warning{{Attempt to free released memory}}
 }
 
 void af2b() {
   int *p = my_malloc(12);
   free(p);
-  my_free(p); // expected-warning{{Try to free a memory block that has been released}}
+  my_free(p); // expected-warning{{Attempt to free released memory}}
 }
 
 void af2c() {
   int *p = my_malloc(12);
   free(p);
-  my_hold(p); // expected-warning{{Try to free a memory block that has been released}}
+  my_hold(p); // expected-warning{{Attempt to free released memory}}
 }
 
 void af2d() {
   int *p = my_malloc(12);
   free(p);
-  my_hold2(0, 0, p); // expected-warning{{Try to free a memory block that has been released}}
+  my_hold2(0, 0, p); // expected-warning{{Attempt to free released memory}}
 }
 
 // No leak if malloc returns null.
@@ -132,7 +132,7 @@
 int * af4() {
   int *p = my_malloc(12);
   my_free(p);
-  return p; // expected-warning{{Use of dynamically allocated}}
+  return p; // expected-warning{{Use of memory after it is freed}}
 }
 
 // This case is (possibly) ok, be conservative
@@ -198,13 +198,13 @@
 void f7() {
   char *x = (char*) malloc(4);
   free(x);
-  x[0] = 'a'; // expected-warning{{Use of dynamically allocated memory after it is freed.}}
+  x[0] = 'a'; // expected-warning{{Use of memory after it is freed}}
 }
 
 void f7_realloc() {
   char *x = (char*) malloc(4);
   realloc(x,0);
-  x[0] = 'a'; // expected-warning{{Use of dynamically allocated memory after it is freed.}}
+  x[0] = 'a'; // expected-warning{{Use of memory after it is freed}}
 }
 
 void PR6123() {

Modified: cfe/trunk/test/Analysis/malloc-plist.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/malloc-plist.c?rev=150733&r1=150732&r2=150733&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/malloc-plist.c (original)
+++ cfe/trunk/test/Analysis/malloc-plist.c Thu Feb 16 16:26:12 2012
@@ -36,7 +36,6 @@
 // CHECK: <dict>
 // CHECK:  <key>files</key>
 // CHECK:  <array>
-// CHECK:   <string>/Users/zaks/workspace/llvmgit/llvm/tools/clang/test/Analysis/malloc-plist.c</string>
 // CHECK:  </array>
 // CHECK:  <key>diagnostics</key>
 // CHECK:  <array>
@@ -259,13 +258,13 @@
 // CHECK:        </array>
 // CHECK:      </array>
 // CHECK:      <key>extended_message</key>
-// CHECK:      <string>Allocated memory never released. Potential memory leak</string>
+// CHECK:      <string>Memory is never released; potential memory leak</string>
 // CHECK:      <key>message</key>
-// CHECK: <string>Allocated memory never released. Potential memory leak</string>
+// CHECK: <string>Memory is never released; potential memory leak</string>
 // CHECK:     </dict>
 // CHECK:    </array>
-// CHECK:    <key>description</key><string>Allocated memory never released. Potential memory leak</string>
-// CHECK:    <key>category</key><string>Logic error</string>
+// CHECK:    <key>description</key><string>Memory is never released; potential memory leak</string>
+// CHECK:    <key>category</key><string>Memory Error</string>
 // CHECK:    <key>type</key><string>Memory leak</string>
 // CHECK:   <key>location</key>
 // CHECK:   <dict>
@@ -416,13 +415,13 @@
 // CHECK:       <key>file</key><integer>0</integer>
 // CHECK:      </dict>
 // CHECK:      <key>extended_message</key>
-// CHECK:      <string>Allocated memory never released. Potential memory leak</string>
+// CHECK:      <string>Memory is never released; potential memory leak</string>
 // CHECK:      <key>message</key>
-// CHECK: <string>Allocated memory never released. Potential memory leak</string>
+// CHECK: <string>Memory is never released; potential memory leak</string>
 // CHECK:     </dict>
 // CHECK:    </array>
-// CHECK:    <key>description</key><string>Allocated memory never released. Potential memory leak</string>
-// CHECK:    <key>category</key><string>Logic error</string>
+// CHECK:    <key>description</key><string>Memory is never released; potential memory leak</string>
+// CHECK:    <key>category</key><string>Memory Error</string>
 // CHECK:    <key>type</key><string>Memory leak</string>
 // CHECK:   <key>location</key>
 // CHECK:   <dict>
@@ -774,13 +773,13 @@
 // CHECK:        </array>
 // CHECK:      </array>
 // CHECK:      <key>extended_message</key>
-// CHECK:      <string>Allocated memory never released. Potential memory leak</string>
+// CHECK:      <string>Memory is never released; potential memory leak</string>
 // CHECK:      <key>message</key>
-// CHECK: <string>Allocated memory never released. Potential memory leak</string>
+// CHECK: <string>Memory is never released; potential memory leak</string>
 // CHECK:     </dict>
 // CHECK:    </array>
-// CHECK:    <key>description</key><string>Allocated memory never released. Potential memory leak</string>
-// CHECK:    <key>category</key><string>Logic error</string>
+// CHECK:    <key>description</key><string>Memory is never released; potential memory leak</string>
+// CHECK:    <key>category</key><string>Memory Error</string>
 // CHECK:    <key>type</key><string>Memory leak</string>
 // CHECK:   <key>location</key>
 // CHECK:   <dict>

Modified: cfe/trunk/test/Analysis/malloc.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/malloc.c?rev=150733&r1=150732&r2=150733&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/malloc.c (original)
+++ cfe/trunk/test/Analysis/malloc.c Thu Feb 16 16:26:12 2012
@@ -15,19 +15,19 @@
 
 void f1() {
   int *p = malloc(12);
-  return; // expected-warning{{Allocated memory never released. Potential memory leak.}}
+  return; // expected-warning{{Memory is never released; potential memory leak}}
 }
 
 void f2() {
   int *p = malloc(12);
   free(p);
-  free(p); // expected-warning{{Try to free a memory block that has been released}}
+  free(p); // expected-warning{{Attempt to free released memory}}
 }
 
 void f2_realloc_0() {
   int *p = malloc(12);
   realloc(p,0);
-  realloc(p,0); // expected-warning{{Try to free a memory block that has been released}}
+  realloc(p,0); // expected-warning{{Attempt to free released memory}}
 }
 
 void f2_realloc_1() {
@@ -40,7 +40,7 @@
   char *p = (char*)malloc(size);
   if (p) {
     char *q = (char*)realloc(p, sizeIn);
-    char x = *q; // expected-warning {{Allocated memory never released.}}
+    char x = *q; // expected-warning {{Memory is never released; potential memory leak}}
   }
 }
 
@@ -79,7 +79,7 @@
   } else {
     free(r);
   }
-  free(p); // expected-warning {{Try to free a memory block that has been released}}
+  free(p); // expected-warning {{Attempt to free released memory}}
 }
 
 void reallocSizeZero3() {
@@ -98,7 +98,7 @@
 }
 
 void reallocPtrZero1() {
-  char *r = realloc(0, 12); // expected-warning {{Allocated memory never released.}}
+  char *r = realloc(0, 12); // expected-warning {{Memory is never released; potential memory leak}}
 }
 
 void reallocPtrZero2() {
@@ -116,7 +116,7 @@
     char *buf = malloc(100);
     buf = (char*)realloc(buf, 0x1000000);
     if (!buf) {
-        return;// expected-warning {{Allocated memory never released.}}
+        return;// expected-warning {{Memory is never released; potential memory leak}}
     }
     free(buf);
 }
@@ -124,7 +124,7 @@
 void reallocRadar6337483_2() {
     char *buf = malloc(100);
     char *buf2 = (char*)realloc(buf, 0x1000000);
-    if (!buf2) { // expected-warning {{Allocated memory never released.}}
+    if (!buf2) { // expected-warning {{Memory is never released; potential memory leak}}
       ;
     } else {
       free(buf2);
@@ -147,7 +147,7 @@
     char *buf = malloc(100);
     char *buf2 = (char*)realloc(buf, 0x1000000);
     if (!buf2) {
-      return;  // expected-warning {{Allocated memory never released.}}
+      return;  // expected-warning {{Memory is never released; potential memory leak}}
     } else {
       free(buf2);
     }
@@ -174,7 +174,7 @@
     char * tmp;
     tmp = (char*)reallocf(buf, 0x1000000);
     if (!tmp) {
-        free(buf); // expected-warning {{Try to free a memory block that has been released}}
+        free(buf); // expected-warning {{Attempt to free released memory}}
         return;
     }
     buf = tmp;
@@ -182,7 +182,7 @@
 }
 
 void reallocfPtrZero1() {
-  char *r = reallocf(0, 12); // expected-warning {{Allocated memory never released.}}
+  char *r = reallocf(0, 12); // expected-warning {{Memory is never released; potential memory leak}}
 }
 
 
@@ -240,13 +240,13 @@
 void f7() {
   char *x = (char*) malloc(4);
   free(x);
-  x[0] = 'a'; // expected-warning{{Use of dynamically allocated memory after it is freed.}}
+  x[0] = 'a'; // expected-warning{{Use of memory after it is freed}}
 }
 
 void f7_realloc() {
   char *x = (char*) malloc(4);
   realloc(x,0);
-  x[0] = 'a'; // expected-warning{{Use of dynamically allocated memory after it is freed.}}
+  x[0] = 'a'; // expected-warning{{Use of memory after it is freed}}
 }
 
 void PR6123() {
@@ -335,14 +335,14 @@
   int *p = malloc(12);
   myfoo(p);
   free(p);
-  free(p); // expected-warning{{Try to free a memory block that has been released}}
+  free(p); // expected-warning{{Attempt to free released memory}}
 }
 
 void mallocEscapeFreeUse() {
   int *p = malloc(12);
   myfoo(p);
   free(p);
-  myfoo(p); // expected-warning{{Use of dynamically allocated memory after it is freed.}}
+  myfoo(p); // expected-warning{{Use of memory after it is freed}}
 }
 
 int *myalloc();
@@ -368,18 +368,18 @@
   int *x = malloc(12);
   int *y = x;
   free(y);
-  myfoo(x); // expected-warning{{Use of dynamically allocated memory after it is freed.}}
+  myfoo(x); // expected-warning{{Use of memory after it is freed}}
 }
 
 void mallocEscapeMalloc() {
   int *p = malloc(12);
   myfoo(p);
-  p = malloc(12); // expected-warning{{Allocated memory never released. Potential memory leak.}}
+  p = malloc(12); // expected-warning{{Memory is never released; potential memory leak}}
 }
 
 void mallocMalloc() {
   int *p = malloc(12);
-  p = malloc(12); // expected-warning{{Allocated memory never released. Potential memory leak}}
+  p = malloc(12); // expected-warning{{Memory is never released; potential memory leak}}
 }
 
 void mallocFreeMalloc() {
@@ -392,13 +392,13 @@
 void mallocFreeUse_params() {
   int *p = malloc(12);
   free(p);
-  myfoo(p); //expected-warning{{Use of dynamically allocated memory after it is freed}}
+  myfoo(p); //expected-warning{{Use of memory after it is freed}}
 }
 
 void mallocFreeUse_params2() {
   int *p = malloc(12);
   free(p);
-  myfooint(*p); //expected-warning{{Use of dynamically allocated memory after it is freed}}
+  myfooint(*p); //expected-warning{{Use of memory after it is freed}}
 }
 
 void mallocFailedOrNot() {
@@ -416,14 +416,14 @@
 int *mallocReturnFreed() {
   int *p = malloc(12);
   free(p);
-  return p; // expected-warning {{Use of dynamically allocated}}
+  return p; // expected-warning {{Use of memory after it is freed}}
 }
 
 int useAfterFreeStruct() {
   struct StructWithInt *px= malloc(sizeof(struct StructWithInt));
   px->g = 5;
   free(px);
-  return px->g; // expected-warning {{Use of dynamically allocated}}
+  return px->g; // expected-warning {{Use of memory after it is freed}}
 }
 
 void nonSymbolAsFirstArg(int *pp, struct StructWithInt *p);
@@ -439,7 +439,7 @@
   if (p == 0)
     return; // no warning
   else
-    return; // expected-warning {{Allocated memory never released. Potential memory leak.}}
+    return; // expected-warning {{Memory is never released; potential memory leak}}
 }
 
 void mallocAssignment() {
@@ -449,14 +449,14 @@
 
 int vallocTest() {
   char *mem = valloc(12);
-  return 0; // expected-warning {{Allocated memory never released. Potential memory leak.}}
+  return 0; // expected-warning {{Memory is never released; potential memory leak}}
 }
 
 void vallocEscapeFreeUse() {
   int *p = valloc(12);
   myfoo(p);
   free(p);
-  myfoo(p); // expected-warning{{Use of dynamically allocated memory after it is freed.}}
+  myfoo(p); // expected-warning{{Use of memory after it is freed}}
 }
 
 int *Gl;
@@ -542,7 +542,7 @@
   struct X *px= malloc(sizeof(struct X));
   px->p = 0;
   px = s2;
-  return px; // expected-warning {{Allocated memory never released. Potential memory leak.}}
+  return px; // expected-warning {{Memory is never released; potential memory leak}}
 }
 
 struct X* RegInvalidationGiveUp1() {
@@ -556,7 +556,7 @@
   int *p = malloc(12);
   pp = &p;
   pp++;
-  return 0;// expected-warning {{Allocated memory never released. Potential memory leak.}}
+  return 0;// expected-warning {{Memory is never released; potential memory leak}}
 }
 
 extern void exit(int) __attribute__ ((__noreturn__));
@@ -602,7 +602,7 @@
   if (p != g)
     free(p);
   else
-    return; // expected-warning{{Allocated memory never released. Potential memory leak}}
+    return; // expected-warning{{Memory is never released; potential memory leak}}
   return;
 }
 
@@ -617,7 +617,7 @@
     p[0] = n;
     p++;
   }
-  return p;// expected-warning {{Allocated memory never released. Potential memory leak.}}
+  return p;// expected-warning {{Memory is never released; potential memory leak}}
 }
 
 // TODO: This is a false positve that should be fixed by making CString checker smarter.





More information about the cfe-commits mailing list