From b831c673621c5587642343cace9def134916a17b Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Tue, 29 Mar 2011 01:40:00 +0000 Subject: [PATCH] Add workaround for Sema issue found in , 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@128443 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Analysis/UninitializedValues.cpp | 16 +++++++++++++--- test/SemaCXX/uninit-variables.cpp | 23 ++++++++++++++++++++++- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/lib/Analysis/UninitializedValues.cpp b/lib/Analysis/UninitializedValues.cpp index 6e7e915c47..f3cf905af2 100644 --- a/lib/Analysis/UninitializedValues.cpp +++ b/lib/Analysis/UninitializedValues.cpp @@ -51,7 +51,7 @@ public: unsigned size() const { return map.size(); } /// Returns the bit vector index for a given declaration. - llvm::Optional getValueIndex(const VarDecl *d); + llvm::Optional getValueIndex(const VarDecl *d) const; }; } @@ -66,8 +66,8 @@ void DeclToIndex::computeMap(const DeclContext &dc) { } } -llvm::Optional DeclToIndex::getValueIndex(const VarDecl *d) { - llvm::DenseMap::iterator I = map.find(d); +llvm::Optional DeclToIndex::getValueIndex(const VarDecl *d) const { + llvm::DenseMap::const_iterator I = map.find(d); if (I == map.end()) return llvm::Optional(); return I->second; @@ -152,6 +152,10 @@ public: 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 @@ public: 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(ac.getDecl())); +#endif } FindVarResult findBlockVarDecl(Expr *ex); diff --git a/test/SemaCXX/uninit-variables.cpp b/test/SemaCXX/uninit-variables.cpp index a016937925..77cbcf72a3 100644 --- a/test/SemaCXX/uninit-variables.cpp +++ b/test/SemaCXX/uninit-variables.cpp @@ -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 @@ test4_A test4() { 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 { + virtual void bar(void) const; +}; +void Rdar9188004C::bar(void) const {} -- 2.40.0