r326520 - [analyzer] Prevent crashing in NonNullParamChecker

George Karpenkov via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 1 16:55:59 PST 2018


Author: george.karpenkov
Date: Thu Mar  1 16:55:59 2018
New Revision: 326520

URL: http://llvm.org/viewvc/llvm-project?rev=326520&view=rev
Log:
[analyzer] Prevent crashing in NonNullParamChecker

https://bugs.llvm.org/show_bug.cgi?id=36381
rdar://37543426

Turns out, the type passed for the lambda capture was incorrect.
One more argument to abandon the getSVal overload which does not require the
type information.

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

Added:
    cfe/trunk/test/Analysis/nonnullparamchecker-crash.cpp
Modified:
    cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp?rev=326520&r1=326519&r2=326520&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp Thu Mar  1 16:55:59 2018
@@ -1405,6 +1405,8 @@ SVal RegionStoreManager::getBinding(Regi
     assert(!T.isNull() && "Unable to auto-detect binding type!");
     assert(!T->isVoidType() && "Attempting to dereference a void pointer!");
     MR = GetElementZeroRegion(cast<SubRegion>(MR), T);
+  } else {
+    T = cast<TypedValueRegion>(MR)->getValueType();
   }
 
   // FIXME: Perhaps this method should just take a 'const MemRegion*' argument

Added: cfe/trunk/test/Analysis/nonnullparamchecker-crash.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/nonnullparamchecker-crash.cpp?rev=326520&view=auto
==============================================================================
--- cfe/trunk/test/Analysis/nonnullparamchecker-crash.cpp (added)
+++ cfe/trunk/test/Analysis/nonnullparamchecker-crash.cpp Thu Mar  1 16:55:59 2018
@@ -0,0 +1,11 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core -verify %s
+class C {};
+
+// expected-no-diagnostics
+void f(C i) {
+  auto lambda = [&] { f(i); };
+  typedef decltype(lambda) T;
+  T* blah = new T(lambda);
+  (*blah)();
+  delete blah;
+}




More information about the cfe-commits mailing list