[cfe-commits] r137068 - in /cfe/trunk: lib/Analysis/UninitializedValues.cpp test/SemaCXX/uninit-variables.cpp

Ted Kremenek kremenek at apple.com
Mon Aug 8 14:43:08 PDT 2011


Author: kremenek
Date: Mon Aug  8 16:43:08 2011
New Revision: 137068

URL: http://llvm.org/viewvc/llvm-project?rev=137068&view=rev
Log:
Fix another -Wuninitialized assertion failure (this one involving bit casts) resulting from the recent -Wuninitialized changes.

Modified:
    cfe/trunk/lib/Analysis/UninitializedValues.cpp
    cfe/trunk/test/SemaCXX/uninit-variables.cpp

Modified: cfe/trunk/lib/Analysis/UninitializedValues.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/UninitializedValues.cpp?rev=137068&r1=137067&r2=137068&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/UninitializedValues.cpp (original)
+++ cfe/trunk/lib/Analysis/UninitializedValues.cpp Mon Aug  8 16:43:08 2011
@@ -389,6 +389,20 @@
 };
 }
 
+static const Expr *stripCasts(ASTContext &C, const Expr *Ex) {
+  while (Ex) {
+    Ex = Ex->IgnoreParenNoopCasts(C);
+    if (const CastExpr *CE = dyn_cast<CastExpr>(Ex)) {
+      if (CE->getCastKind() == CK_LValueBitCast) {
+        Ex = CE->getSubExpr();
+        continue;
+      }
+    }
+    break;
+  }
+  return Ex;
+}
+
 void TransferFunctions::reportUninit(const DeclRefExpr *ex,
                                      const VarDecl *vd, bool isAlwaysUnit) {
   if (handler) handler->handleUseOfUninitVariable(ex, vd, isAlwaysUnit);
@@ -470,9 +484,9 @@
           // appropriately, but we need to continue to analyze subsequent uses
           // of the variable.
           if (init == lastLoad) {
-            DeclRefExpr *DR
-              = cast<DeclRefExpr>(lastLoad->
-                  getSubExpr()->IgnoreParenNoopCasts(ac.getASTContext()));
+            const DeclRefExpr *DR
+              = cast<DeclRefExpr>(stripCasts(ac.getASTContext(),
+                                             lastLoad->getSubExpr()));
             if (DR->getDecl() == vd) {
               // int x = x;
               // Propagate uninitialized value, but don't immediately report
@@ -544,7 +558,8 @@
       }
     }
   }
-  else if (ce->getCastKind() == CK_NoOp) {
+  else if (ce->getCastKind() == CK_NoOp ||
+           ce->getCastKind() == CK_LValueBitCast) {
     skipProcessUses = true;
   }
   else if (CStyleCastExpr *cse = dyn_cast<CStyleCastExpr>(ce)) {
@@ -580,10 +595,10 @@
     // If we reach here, we have seen a load of an uninitialized value
     // and it hasn't been casted to void or otherwise handled.  In this
     // situation, report the incident.
-    DeclRefExpr *DR =
-      cast<DeclRefExpr>(lastLoad->getSubExpr()->
-                          IgnoreParenNoopCasts(ac.getASTContext()));
-    VarDecl *VD = cast<VarDecl>(DR->getDecl());
+    const DeclRefExpr *DR =
+      cast<DeclRefExpr>(stripCasts(ac.getASTContext(),
+                                   lastLoad->getSubExpr()));
+    const VarDecl *VD = cast<VarDecl>(DR->getDecl());
     reportUninit(DR, VD, isAlwaysUninit(vals[VD]));
     lastLoad = 0;
     

Modified: cfe/trunk/test/SemaCXX/uninit-variables.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/uninit-variables.cpp?rev=137068&r1=137067&r2=137068&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/uninit-variables.cpp (original)
+++ cfe/trunk/test/SemaCXX/uninit-variables.cpp Mon Aug  8 16:43:08 2011
@@ -130,3 +130,14 @@
     int y = (int&)x; // expected-warning {{uninitialized when used here}}
 }
 
+// Test handling of bit casts.
+void test_bitcasts() {
+  int x = 1;
+  int y = (float &)x; // no-warning
+}
+
+void test_bitcasts_2() {
+  int x;  // expected-note {{declared here}} expected-note {{add initialization}}
+  int y = (float &)x; // expected-warning {{uninitialized when used here}}
+}
+





More information about the cfe-commits mailing list