[PATCH] D28297: [StaticAnalyzer] Fix crash in CastToStructChecker

Daniel Marjamäki via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Feb 18 03:30:43 PST 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rL295545: [analyzer] Fix crash in CastToStruct when there is no record definition (authored by danielmarjamaki).

Changed prior to commit:
  https://reviews.llvm.org/D28297?vs=83062&id=89019#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D28297

Files:
  cfe/trunk/lib/StaticAnalyzer/Checkers/CastToStructChecker.cpp
  cfe/trunk/test/Analysis/cast-to-struct.cpp


Index: cfe/trunk/lib/StaticAnalyzer/Checkers/CastToStructChecker.cpp
===================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/CastToStructChecker.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/CastToStructChecker.cpp
@@ -84,6 +84,13 @@
     if (!VD || VD->getType()->isReferenceType())
       return true;
 
+    // Don't warn when target type has no definition.
+    if (const RecordType *RD = dyn_cast<RecordType>(ToPointeeTy.getTypePtr())) {
+      if (!RD->getDecl()->getDefinition()) {
+        return true;
+      }
+    }
+
     // Warn when there is widening cast.
     unsigned ToWidth = Ctx.getTypeInfo(ToPointeeTy).Width;
     unsigned OrigWidth = Ctx.getTypeInfo(OrigPointeeTy).Width;
Index: cfe/trunk/test/Analysis/cast-to-struct.cpp
===================================================================
--- cfe/trunk/test/Analysis/cast-to-struct.cpp
+++ cfe/trunk/test/Analysis/cast-to-struct.cpp
@@ -65,3 +65,8 @@
   void *VP = P;
   Abc = (struct ABC *)VP;
 }
+
+// https://llvm.org/bugs/show_bug.cgi?id=31173
+void dontCrash(struct AB X) {
+  struct UndefS *S = (struct UndefS *)&X;
+}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D28297.89019.patch
Type: text/x-patch
Size: 1153 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170218/3b8157a2/attachment.bin>


More information about the cfe-commits mailing list