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

Ted Kremenek kremenek at apple.com
Mon Mar 28 18:40:00 PDT 2011


Author: kremenek
Date: Mon Mar 28 20:40:00 2011
New Revision: 128443

URL: http://llvm.org/viewvc/llvm-project?rev=128443&view=rev
Log:
Add workaround for Sema issue found in <rdar://problem/9188004>, which leads to an assertion failure in the uninitialized variables analysis.  The problem is that Sema isn't properly registering a variable in a DeclContext (which -Wuninitialized relies on), but
my expertise on the template instantiation logic isn't good enough to fix this problem for real.  This patch worksaround the
problem in -Wuninitialized, but we should fix it for real later.

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=128443&r1=128442&r2=128443&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/UninitializedValues.cpp (original)
+++ cfe/trunk/lib/Analysis/UninitializedValues.cpp Mon Mar 28 20:40:00 2011
@@ -51,7 +51,7 @@
   unsigned size() const { return map.size(); }
   
   /// Returns the bit vector index for a given declaration.
-  llvm::Optional<unsigned> getValueIndex(const VarDecl *d);
+  llvm::Optional<unsigned> getValueIndex(const VarDecl *d) const;
 };
 }
 
@@ -66,8 +66,8 @@
   }
 }
 
-llvm::Optional<unsigned> DeclToIndex::getValueIndex(const VarDecl *d) {
-  llvm::DenseMap<const VarDecl *, unsigned>::iterator I = map.find(d);
+llvm::Optional<unsigned> DeclToIndex::getValueIndex(const VarDecl *d) const {
+  llvm::DenseMap<const VarDecl *, unsigned>::const_iterator I = map.find(d);
   if (I == map.end())
     return llvm::Optional<unsigned>();
   return I->second;
@@ -152,6 +152,10 @@
     return declToIndex.size() == 0;
   }
   
+  bool hasEntry(const VarDecl *vd) const {
+    return declToIndex.getValueIndex(vd).hasValue();
+  }
+  
   void resetScratch();
   ValueVector &getScratch() { return scratch; }
   
@@ -379,7 +383,13 @@
   void BlockStmt_VisitObjCForCollectionStmt(ObjCForCollectionStmt *fs);
   
   bool isTrackedVar(const VarDecl *vd) {
+#if 1
+    // FIXME: This is a temporary workaround to deal with the fact
+    // that DeclContext's do not always contain all of their variables!
+    return vals.hasEntry(vd);
+#else
     return ::isTrackedVar(vd, cast<DeclContext>(ac.getDecl()));
+#endif
   }
   
   FindVarResult findBlockVarDecl(Expr *ex);

Modified: cfe/trunk/test/SemaCXX/uninit-variables.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/uninit-variables.cpp?rev=128443&r1=128442&r2=128443&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/uninit-variables.cpp (original)
+++ cfe/trunk/test/SemaCXX/uninit-variables.cpp Mon Mar 28 20:40:00 2011
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -Wuninitialized -fsyntax-only %s -verify
+// RUN: %clang_cc1 -fsyntax-only -Wuninitialized -fsyntax-only -fcxx-exceptions %s -verify
 
 int test1_aux(int &x);
 int test1() {
@@ -49,3 +49,24 @@
  return a; // expected-warning{{variable 'a' is possibly uninitialized when used here}}
 }
 
+// This test previously crashed Sema.
+class Rdar9188004A {
+public: 
+  virtual ~Rdar9188004A();
+};
+
+template< typename T > class Rdar9188004B : public Rdar9188004A {
+virtual double *foo(Rdar9188004B *next) const  {
+    double *values = next->foo(0);
+    try {
+    }
+    catch(double e) {
+      values[0] = e;
+    }
+    return 0;
+  }
+};
+class Rdar9188004C : public Rdar9188004B<Rdar9188004A> {
+  virtual void bar(void) const;
+};
+void Rdar9188004C::bar(void) const {}





More information about the cfe-commits mailing list