]> granicus.if.org Git - clang/commitdiff
Teach -Wuninitialized-experimental about sizeof().
authorTed Kremenek <kremenek@apple.com>
Sun, 23 Jan 2011 17:53:04 +0000 (17:53 +0000)
committerTed Kremenek <kremenek@apple.com>
Sun, 23 Jan 2011 17:53:04 +0000 (17:53 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@124076 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/UninitializedValuesV2.cpp
test/Sema/uninit-variables.c

index dfaff314e2f92f5ceef2b2a11a28fd36f0260d3c..4c54885413195c59cce6d61b9b180c26229b174b 100644 (file)
@@ -302,6 +302,7 @@ public:
   void VisitUnaryOperator(UnaryOperator *uo);
   void VisitBinaryOperator(BinaryOperator *bo);
   void VisitCastExpr(CastExpr *ce);
+  void VisitSizeOfAlignOfExpr(SizeOfAlignOfExpr *se);
 };
 }
 
@@ -435,6 +436,15 @@ void TransferFunctions::VisitCastExpr(clang::CastExpr *ce) {
   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.
 //====------------------------------------------------------------------------//
index aed7a709660f542164fb90ff92eff28f158c843c..faf94c024bc63117340aba17d147cc940e4d7e0e 100644 (file)
@@ -180,3 +180,15 @@ MyInt test26() {
   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}}
+}
+