[cfe-commits] r61039 - in /cfe/trunk: lib/Analysis/GRExprEngine.cpp test/Analysis/misc-ps.m

Ted Kremenek kremenek at apple.com
Mon Dec 15 10:51:00 PST 2008


Author: kremenek
Date: Mon Dec 15 12:51:00 2008
New Revision: 61039

URL: http://llvm.org/viewvc/llvm-project?rev=61039&view=rev
Log:
Fix regression in handling sizeof(void) in the static analyzer.

Modified:
    cfe/trunk/lib/Analysis/GRExprEngine.cpp
    cfe/trunk/test/Analysis/misc-ps.m

Modified: cfe/trunk/lib/Analysis/GRExprEngine.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/GRExprEngine.cpp?rev=61039&r1=61038&r2=61039&view=diff

==============================================================================
--- cfe/trunk/lib/Analysis/GRExprEngine.cpp (original)
+++ cfe/trunk/lib/Analysis/GRExprEngine.cpp Mon Dec 15 12:51:00 2008
@@ -1973,22 +1973,24 @@
   uint64_t amt;  
   
   if (Ex->isSizeOf()) {
-
-    // FIXME: Add support for VLAs.
-    if (!T.getTypePtr()->isConstantSizeType())
+    if (T == getContext().VoidTy) {          
+      // sizeof(void) == 1 byte.
+      amt = 1;
+    }
+    else if (!T.getTypePtr()->isConstantSizeType()) {
+      // FIXME: Add support for VLAs.
       return;
-    
-    // Some code tries to take the sizeof an ObjCInterfaceType, relying that
-    // the compiler has laid out its representation.  Just report Unknown
-    // for these.
-    if (T->isObjCInterfaceType())
+    }
+    else if (T->isObjCInterfaceType()) {
+      // Some code tries to take the sizeof an ObjCInterfaceType, relying that
+      // the compiler has laid out its representation.  Just report Unknown
+      // for these.      
       return;
-    
-    amt = 1;  // Handle sizeof(void)
-    
-    if (T != getContext().VoidTy)
+    }
+    else {
+      // All other cases.
       amt = getContext().getTypeSize(T) / 8;
-    
+    }    
   }
   else  // Get alignment of the type.
     amt = getContext().getTypeAlign(T) / 8;

Modified: cfe/trunk/test/Analysis/misc-ps.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/misc-ps.m?rev=61039&r1=61038&r2=61039&view=diff

==============================================================================
--- cfe/trunk/test/Analysis/misc-ps.m (original)
+++ cfe/trunk/test/Analysis/misc-ps.m Mon Dec 15 12:51:00 2008
@@ -87,3 +87,28 @@
   int vla[x]; // expected-warning{{The expression used to specify the number of elements in the VLA 'vla' evaluates to an undefined or garbage value.}}
 }
 
+// sizeof(void)
+// - Tests a regression reported in PR 3211: http://llvm.org/bugs/show_bug.cgi?id=3211
+void handle_sizeof_void(unsigned flag) {
+  int* p = 0;
+
+  if (flag) {
+    if (sizeof(void) == 1)
+      return;
+    // Infeasible.
+    *p = 1; // no-warning
+  }
+  
+  void* q;
+  
+  if (!flag) {
+    if (sizeof(*q) == 1)
+      return;
+    // Infeasibe.
+    *p = 1; // no-warning
+  }
+    
+  // Infeasible.
+  *p = 1; // no-warning
+}
+





More information about the cfe-commits mailing list