[PATCH] D42396: [analyzer] Do not attempt to get the pointee of void* .
Alexander Shaposhnikov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 24 14:19:24 PST 2018
This revision was automatically updated to reflect the committed changes.
Closed by commit rL323382: [analyzer] Do not attempt to get the pointee of void* (authored by alexshap, committed by ).
Changed prior to commit:
https://reviews.llvm.org/D42396?vs=130979&id=131352#toc
Repository:
rL LLVM
https://reviews.llvm.org/D42396
Files:
cfe/trunk/lib/StaticAnalyzer/Core/PathDiagnostic.cpp
cfe/trunk/test/Analysis/malloc.c
Index: cfe/trunk/lib/StaticAnalyzer/Core/PathDiagnostic.cpp
===================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/PathDiagnostic.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/PathDiagnostic.cpp
@@ -1211,6 +1211,9 @@
// Check if the parameter is a pointer to the symbol.
if (Optional<loc::MemRegionVal> Reg = SV.getAs<loc::MemRegionVal>()) {
+ // Do not attempt to dereference void*.
+ if ((*I)->getType()->isVoidPointerType())
+ continue;
SVal PSV = N->getState()->getSVal(Reg->getRegion());
SymbolRef AS = PSV.getAsLocSymbol();
if (AS == Sym) {
Index: cfe/trunk/test/Analysis/malloc.c
===================================================================
--- cfe/trunk/test/Analysis/malloc.c
+++ cfe/trunk/test/Analysis/malloc.c
@@ -1786,6 +1786,18 @@
free(p);
}
+void allocateSomeMemory(void *offendingParameter, void **ptr) {
+ *ptr = malloc(1);
+}
+
+void testNoCrashOnOffendingParameter() {
+ // "extern" is necessary to avoid unrelated warnings
+ // on passing uninitialized value.
+ extern void *offendingParameter;
+ void* ptr;
+ allocateSomeMemory(offendingParameter, &ptr);
+} // expected-warning {{Potential leak of memory pointed to by 'ptr'}}
+
// ----------------------------------------------------------------------------
// False negatives.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D42396.131352.patch
Type: text/x-patch
Size: 1371 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180124/e46d7d5e/attachment.bin>
More information about the llvm-commits
mailing list