]> granicus.if.org Git - clang/commitdiff
Fix an invalid use of ::back() on an newly emptied vector. Also tighten
authorChandler Carruth <chandlerc@gmail.com>
Tue, 28 Jun 2011 21:43:34 +0000 (21:43 +0000)
committerChandler Carruth <chandlerc@gmail.com>
Tue, 28 Jun 2011 21:43:34 +0000 (21:43 +0000)
up several places where we never expect to have NULL pointers to assert
early.

This fixes a valgrind error within CorrectTypo, but not the
non-determinism.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@134032 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaLookup.cpp

index a92c9eeb8f0ff89d756f8430e249a43031cc7bb8..6fa7cd673ceabf360146a7047c1d0ce5dd06d8a4 100644 (file)
@@ -3237,6 +3237,7 @@ class NamespaceSpecifierSet {
 }
 
 DeclContextList NamespaceSpecifierSet::BuildContextChain(DeclContext *Start) {
+  assert(Start && "Bulding a context chain from a null context");
   DeclContextList Chain;
   for (DeclContext *DC = Start->getPrimaryContext(); DC != NULL;
        DC = DC->getLookupParent()) {
@@ -3267,7 +3268,7 @@ void NamespaceSpecifierSet::SortNamespaces() {
 }
 
 void NamespaceSpecifierSet::AddNamespace(NamespaceDecl *ND) {
-  DeclContext *Ctx = dyn_cast<DeclContext>(ND);
+  DeclContext *Ctx = cast<DeclContext>(ND);
   NestedNameSpecifier *NNS = NULL;
   unsigned NumSpecifiers = 0;
   DeclContextList NamespaceDeclChain(BuildContextChain(Ctx));
@@ -3275,7 +3276,8 @@ void NamespaceSpecifierSet::AddNamespace(NamespaceDecl *ND) {
   // Eliminate common elements from the two DeclContext chains
   for (DeclContextList::reverse_iterator C = CurContextChain.rbegin(),
                                       CEnd = CurContextChain.rend();
-       C != CEnd && NamespaceDeclChain.back() == *C; ++C) {
+       C != CEnd && !NamespaceDeclChain.empty() &&
+       NamespaceDeclChain.back() == *C; ++C) {
     NamespaceDeclChain.pop_back();
   }