This revision was automatically updated to reflect the committed changes.
Closed by commit rL297187: [analyzer] Fix crashes in CastToStruct checker for 
undefined structs (authored by danielmarjamaki).

Changed prior to commit:
  https://reviews.llvm.org/D28297?vs=89507&id=90900#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/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,17 @@
   void *VP = P;
   Abc = (struct ABC *)VP;
 }
+
+// https://llvm.org/bugs/show_bug.cgi?id=31173
+void dontCrash1(struct AB X) {
+  struct UndefS *S = (struct UndefS *)&X;
+}
+
+struct S;
+struct T {
+  struct S *P;
+};
+extern struct S Var1, Var2;
+void dontCrash2() {
+  ((struct T *) &Var1)->P = &Var2;
+}
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,10 @@
     if (!VD || VD->getType()->isReferenceType())
       return true;
 
+    if (ToPointeeTy->isIncompleteType() ||
+        OrigPointeeTy->isIncompleteType())
+      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,17 @@
   void *VP = P;
   Abc = (struct ABC *)VP;
 }
+
+// https://llvm.org/bugs/show_bug.cgi?id=31173
+void dontCrash1(struct AB X) {
+  struct UndefS *S = (struct UndefS *)&X;
+}
+
+struct S;
+struct T {
+  struct S *P;
+};
+extern struct S Var1, Var2;
+void dontCrash2() {
+  ((struct T *) &Var1)->P = &Var2;
+}
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,10 @@
     if (!VD || VD->getType()->isReferenceType())
       return true;
 
+    if (ToPointeeTy->isIncompleteType() ||
+        OrigPointeeTy->isIncompleteType())
+      return true;
+
     // Warn when there is widening cast.
     unsigned ToWidth = Ctx.getTypeInfo(ToPointeeTy).Width;
     unsigned OrigWidth = Ctx.getTypeInfo(OrigPointeeTy).Width;
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to