Author: kremenek
Date: Sun Jan 23 11:53:04 2011
New Revision: 124076

URL: http://llvm.org/viewvc/llvm-project?rev=124076&view=rev
Log:
Teach -Wuninitialized-experimental about sizeof().

Modified:
    cfe/trunk/lib/Analysis/UninitializedValuesV2.cpp
    cfe/trunk/test/Sema/uninit-variables.c

Modified: cfe/trunk/lib/Analysis/UninitializedValuesV2.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/UninitializedValuesV2.cpp?rev=124076&r1=124075&r2=124076&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/UninitializedValuesV2.cpp (original)
+++ cfe/trunk/lib/Analysis/UninitializedValuesV2.cpp Sun Jan 23 11:53:04 2011
@@ -302,6 +302,7 @@
   void VisitUnaryOperator(UnaryOperator *uo);
   void VisitBinaryOperator(BinaryOperator *bo);
   void VisitCastExpr(CastExpr *ce);
+  void VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *se);
 };
 }
 
@@ -435,6 +436,15 @@
   Visit(ce->getSubExpr());
 }
 
+void TransferFunctions::VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *se) {
+  if (se->isSizeOf()) {
+    if (se->getType()->isConstantSizeType())
+      return;
+    // Handle VLAs.
+    Visit(se->getArgumentExpr());
+  }
+}
+
 
//------------------------------------------------------------------------====//
 // High-level "driver" logic for uninitialized values analysis.
 
//====------------------------------------------------------------------------//

Modified: cfe/trunk/test/Sema/uninit-variables.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/uninit-variables.c?rev=124076&r1=124075&r2=124076&view=diff
==============================================================================
--- cfe/trunk/test/Sema/uninit-variables.c (original)
+++ cfe/trunk/test/Sema/uninit-variables.c Sun Jan 23 11:53:04 2011
@@ -180,3 +180,15 @@
   MyInt x; // expected-warning{{use of uninitialized variable 'x'}} 
expected-note{{add initialization to silence this warning}}
   return x; // expected-note{{variable 'x' is possibly uninitialized when used 
here}}
 }
+
+// Test handling of sizeof().
+int test27() {
+  struct test_27 { int x; } *y;
+  return sizeof(y->x); // no-warning
+}
+
+int test28() {
+  int len; // expected-warning{{use of uninitialized variable 'len'}} 
expected-note{{add initialization to silence this warning}}
+  return sizeof(int[len]); // expected-note{{variable 'len' is possibly 
uninitialized when used here}}
+}
+


_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to