[cfe-commits] r134032 - /cfe/trunk/lib/Sema/SemaLookup.cpp

Chandler Carruth chandlerc at gmail.com
Tue Jun 28 14:43:35 PDT 2011


Author: chandlerc
Date: Tue Jun 28 16:43:34 2011
New Revision: 134032

URL: http://llvm.org/viewvc/llvm-project?rev=134032&view=rev
Log:
Fix an invalid use of ::back() on an newly emptied vector. Also tighten
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.

Modified:
    cfe/trunk/lib/Sema/SemaLookup.cpp

Modified: cfe/trunk/lib/Sema/SemaLookup.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaLookup.cpp?rev=134032&r1=134031&r2=134032&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaLookup.cpp (original)
+++ cfe/trunk/lib/Sema/SemaLookup.cpp Tue Jun 28 16:43:34 2011
@@ -3237,6 +3237,7 @@
 }
 
 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::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 @@
   // 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();
   }
 





More information about the cfe-commits mailing list