[cfe-commits] r146816 - /cfe/trunk/include/clang/AST/Redeclarable.h

Argyrios Kyrtzidis akyrtzi at gmail.com
Fri Dec 16 20:13:25 PST 2011


Author: akirtzidis
Date: Fri Dec 16 22:13:25 2011
New Revision: 146816

URL: http://llvm.org/viewvc/llvm-project?rev=146816&view=rev
Log:
Add a sanity check in the Redeclarable::redecl_iterator to avoid infinite loop
when we formed an invalid redeclaration chain due to a bug.

Thanks to Doug for the hint!

Modified:
    cfe/trunk/include/clang/AST/Redeclarable.h

Modified: cfe/trunk/include/clang/AST/Redeclarable.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Redeclarable.h?rev=146816&r1=146815&r2=146816&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Redeclarable.h (original)
+++ cfe/trunk/include/clang/AST/Redeclarable.h Fri Dec 16 22:13:25 2011
@@ -116,6 +116,7 @@
     /// Current - The current declaration.
     decl_type *Current;
     decl_type *Starter;
+    bool PassedFirst;
 
   public:
     typedef decl_type*                value_type;
@@ -125,13 +126,24 @@
     typedef std::ptrdiff_t            difference_type;
 
     redecl_iterator() : Current(0) { }
-    explicit redecl_iterator(decl_type *C) : Current(C), Starter(C) { }
+    explicit redecl_iterator(decl_type *C)
+      : Current(C), Starter(C), PassedFirst(false) { }
 
     reference operator*() const { return Current; }
     pointer operator->() const { return Current; }
 
     redecl_iterator& operator++() {
       assert(Current && "Advancing while iterator has reached end");
+      // Sanity check to avoid infinite loop on invalid redecl chain.
+      if (Current->isFirstDeclaration()) {
+        if (PassedFirst) {
+          assert(0 && "Passed first decl twice, invalid redecl chain!");
+          Current = 0;
+          return *this;
+        }
+        PassedFirst = true;
+      }
+
       // Get either previous decl or latest decl.
       decl_type *Next = Current->RedeclLink.getNext();
       Current = (Next != Starter ? Next : 0);





More information about the cfe-commits mailing list