r369726 - [analyzer] DynamicTypeInfo: Avoid putting null regions into dynamic typemap.

Artem Dergachev via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 22 20:23:55 PDT 2019


Author: dergachev
Date: Thu Aug 22 20:23:55 2019
New Revision: 369726

URL: http://llvm.org/viewvc/llvm-project?rev=369726&view=rev
Log:
[analyzer] DynamicTypeInfo: Avoid putting null regions into dynamic typemap.

Fixes a crash.

Modified:
    cfe/trunk/lib/StaticAnalyzer/Core/DynamicType.cpp
    cfe/trunk/test/Analysis/cast-value-logic.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Core/DynamicType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/DynamicType.cpp?rev=369726&r1=369725&r2=369726&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/DynamicType.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/DynamicType.cpp Thu Aug 22 20:23:55 2019
@@ -93,6 +93,9 @@ ProgramStateRef setDynamicTypeAndCastInf
                                           QualType CastFromTy,
                                           QualType CastToTy, QualType ResultTy,
                                           bool CastSucceeds) {
+  if (!MR)
+    return State;
+
   if (CastSucceeds)
     State = State->set<DynamicTypeMap>(MR, ResultTy);
 

Modified: cfe/trunk/test/Analysis/cast-value-logic.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/cast-value-logic.cpp?rev=369726&r1=369725&r2=369726&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/cast-value-logic.cpp (original)
+++ cfe/trunk/test/Analysis/cast-value-logic.cpp Thu Aug 22 20:23:55 2019
@@ -131,3 +131,8 @@ void evalLogic(const Shape *S) {
 }
 } // namespace test_get_as
 
+namespace crashes {
+void test_non_reference_null_region_crash(Shape s) {
+  cast<Circle>(s); // no-crash
+}
+} // namespace crashes




More information about the cfe-commits mailing list