r335700 - [analyzer] [NFC] Add -verify to malloc checker test

George Karpenkov via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 26 18:51:37 PDT 2018


Author: george.karpenkov
Date: Tue Jun 26 18:51:36 2018
New Revision: 335700

URL: http://llvm.org/viewvc/llvm-project?rev=335700&view=rev
Log:
[analyzer] [NFC] Add -verify to malloc checker test

Differential Revision: https://reviews.llvm.org/D48514

Modified:
    cfe/trunk/test/Analysis/malloc-plist.c

Modified: cfe/trunk/test/Analysis/malloc-plist.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/malloc-plist.c?rev=335700&r1=335699&r2=335700&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/malloc-plist.c (original)
+++ cfe/trunk/test/Analysis/malloc-plist.c Tue Jun 26 18:51:36 2018
@@ -1,5 +1,5 @@
 // RUN: rm -f %t
-// RUN: %clang_analyze_cc1 -fblocks -analyzer-checker=core,unix.Malloc -analyzer-output=plist -o %t %s
+// RUN: %clang_analyze_cc1 -fblocks -analyzer-checker=core,unix.Malloc -analyzer-output=plist -verify -o %t %s
 // RUN: FileCheck -input-file %t %s
 
 typedef __typeof(sizeof(int)) size_t;
@@ -19,8 +19,8 @@ void diagnosticTest(int in) {
 void myArrayAllocation() {
     int **A;
     A = malloc(2*sizeof(int*));
-    A[0] = 0;// expected-warning {{leak}}
-}
+    A[0] = 0;
+}//expected-warning{{Potential leak}}
 
 void reallocDiagnostics() {
     char * buf = malloc(100);
@@ -44,7 +44,7 @@ void *wrapper() {
 void test_wrapper() {
   void *buf = wrapper();
   (void) buf;
-}
+}//expected-warning{{Potential leak}}
 
 // Test what happens when the same call frees and allocated memory.
 // Also tests the stack hint for parameters, when they are passed directly or via pointer.
@@ -60,7 +60,7 @@ void my_malloc_and_free(void **x) {
 void *test_double_action_call() {
     void *buf;
     my_malloc_and_free(&buf);
-    return buf;
+    return buf; //expected-warning{{Use of memory after it is freed}}
 }
 
 // Test stack hint for 'reallocation failed'.
@@ -75,7 +75,7 @@ char *my_realloc(char *buf) {
 void reallocIntra() {
     char *buf = (char *)malloc(100);
     buf = my_realloc(buf);
-    free(buf);
+    free(buf);//expected-warning{{Potential leak}}
 }
 
 // Test stack hint when returning a result.
@@ -85,7 +85,7 @@ static char *malloc_wrapper_ret() {
 void use_ret() {
     char *v;
     v = malloc_wrapper_ret();
-}
+}//expected-warning{{Potential leak}}
 
 // Passing a block as a parameter to an inlined call for which we generate
 // a stack hint message caused crashes.
@@ -99,7 +99,7 @@ void call_myfree_takingblock() {
 
   int *p = malloc(sizeof(int));
   myfree_takingblock(some_block, p);
-  *p = 3;
+  *p = 3;//expected-warning{{Use of memory after it is freed}}
 }
 
 // Test that we refer to the last symbol used in the leak diagnostic.
@@ -112,13 +112,13 @@ void LeakedSymbol(int in) {
     m = p;
     p = 0;
     (*m)++;
-    in++;
+    in++;//expected-warning{{Potential leak}}
 }
 
 // Tests that exercise running remove dead bindings at Call exit.
 static void function_with_leak1() {
     char *x = (char*)malloc(12);
-}
+} //expected-warning{{Potential leak}}
 void use_function_with_leak1() {
     function_with_leak1();
     int y = 0;
@@ -126,7 +126,7 @@ void use_function_with_leak1() {
 
 static void function_with_leak2() {
     char *x = (char*)malloc(12);
-    int m = 0;
+    int m = 0; //expected-warning{{Potential leak}}
 }
 void use_function_with_leak2() {
     function_with_leak2();
@@ -136,7 +136,7 @@ static void function_with_leak3(int y) {
     char *x = (char*)malloc(12);
     if (y)
         y++;
-}
+}//expected-warning{{Potential leak}}
 void use_function_with_leak3(int y) {
     function_with_leak3(y);
 }
@@ -146,7 +146,7 @@ static void function_with_leak4(int y) {
     if (y)
         y++;
     else
-        y--;
+        y--;//expected-warning{{Potential leak}}
 }
 void use_function_with_leak4(int y) {
     function_with_leak4(y);
@@ -157,7 +157,7 @@ int anotherFunction5() {
 }
 static int function_with_leak5() {
     char *x = (char*)malloc(12);
-    return anotherFunction5();
+    return anotherFunction5();//expected-warning{{Potential leak}}
 }
 void use_function_with_leak5() {
     function_with_leak5();
@@ -168,7 +168,7 @@ void anotherFunction6(int m) {
 }
 static void function_with_leak6() {
     char *x = (char*)malloc(12);
-    anotherFunction6(3);
+    anotherFunction6(3);//expected-warning{{Potential leak}}
 }
 void use_function_with_leak6() {
     function_with_leak6();
@@ -184,7 +184,7 @@ static char *function_with_leak7() {
 }
 void use_function_with_leak7() {
     function_with_leak7();
-}
+}//expected-warning{{Potential memory leak}}
 
 // Test that we do not print the name of a variable not visible from where
 // the issue is reported.
@@ -194,7 +194,7 @@ int *my_malloc() {
 }
 void testOnlyRefferToVisibleVariables() {
   my_malloc();
-} // expected-warning {{Potential leak of memory}}
+} // expected-warning{{Potential memory leak}}
 
 struct PointerWrapper{
   int*p;
@@ -205,8 +205,8 @@ int *my_malloc_into_struct() {
   return w.p;
 }
 void testMyMalloc() {
-  my_malloc_into_struct(); // expected-warning {{Potential leak of memory}}
-}
+  my_malloc_into_struct();
+} // expected-warning{{Potential memory leak}}
 
 // CHECK:   <key>diagnostics</key>
 // CHECK-NEXT:   <array>




More information about the cfe-commits mailing list