[PATCH] D99959: [analyzer][NFC] Add tests for extents

Balázs Benics via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 6 08:00:29 PDT 2021


steakhal created this revision.
steakhal added reviewers: NoQ, vsavchenko, Charusso.
Herald added subscribers: ASDenysPetrov, martong, dkrupp, donat.nagy, Szelethus, mikhail.ramalho, a.sidorin, szepet, baloghadamsoftware, xazax.hun, whisperity.
Herald added a reviewer: Szelethus.
steakhal requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D99959

Files:
  clang/test/Analysis/malloc.c


Index: clang/test/Analysis/malloc.c
===================================================================
--- clang/test/Analysis/malloc.c
+++ 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 @@
   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);
+}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D99959.335511.patch
Type: text/x-patch
Size: 936 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210406/bd0d2c9b/attachment.bin>


More information about the cfe-commits mailing list