[clang] f0e102c - [analyzer][NFC] Add tests for extents

Balazs Benics via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 7 04:45:28 PDT 2021


Author: Balazs Benics
Date: 2021-04-07T13:43:19+02:00
New Revision: f0e102c1a39f0f7e9e309b27916533b8fefd9be7

URL: https://github.com/llvm/llvm-project/commit/f0e102c1a39f0f7e9e309b27916533b8fefd9be7
DIFF: https://github.com/llvm/llvm-project/commit/f0e102c1a39f0f7e9e309b27916533b8fefd9be7.diff

LOG: [analyzer][NFC] Add tests for extents

If we allocate memory, the extent of the MemRegion will be the symbolic
value of the size parameter. This way, if that symbol gets constrained,
the extent will be also constrained.

This test demonstrates that the extent is indeed the same symbol.

Reviewed By: NoQ

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

Added: 
    

Modified: 
    clang/test/Analysis/malloc.c

Removed: 
    


################################################################################
diff  --git a/clang/test/Analysis/malloc.c b/clang/test/Analysis/malloc.c
index 9961c471bd7d..add5dc7fe8c2 100644
--- a/clang/test/Analysis/malloc.c
+++ b/clang/test/Analysis/malloc.c
@@ -8,6 +8,8 @@
 #include "Inputs/system-header-simulator.h"
 
 void clang_analyzer_eval(int);
+void clang_analyzer_dump(int);
+void clang_analyzer_dumpExtent(void *);
 
 // Without -fms-compatibility, wchar_t isn't a builtin type. MSVC defines
 // _WCHAR_T_DEFINED if wchar_t is available. Microsoft recommends that you use
@@ -1883,3 +1885,14 @@ void testMallocIntoMalloc() {
   s->memP = malloc(sizeof(int));
   free(s);
 } // FIXME: should warn here
+
+int conjure();
+void testExtent() {
+  int x = conjure();
+  clang_analyzer_dump(x);
+  // expected-warning-re at -1 {{{{^conj_\$[[:digit:]]+{int, LC1, S[[:digit:]]+, #1}}}}}}
+  int *p = (int *)malloc(x);
+  clang_analyzer_dumpExtent(p);
+  // expected-warning-re at -1 {{{{^conj_\$[[:digit:]]+{int, LC1, S[[:digit:]]+, #1}}}}}}
+  free(p);
+}


        


More information about the cfe-commits mailing list