[cfe-commits] r130788 - /cfe/trunk/lib/Sema/SemaDeclCXX.cpp

Sean Hunt scshunt at csclub.uwaterloo.ca
Tue May 3 13:43:02 PDT 2011


Author: coppro
Date: Tue May  3 15:43:02 2011
New Revision: 130788

URL: http://llvm.org/viewvc/llvm-project?rev=130788&view=rev
Log:
Move the AST modifications to after the cycle detection in
lib/Sema/SemaDeclCXX.cpp to avoid getting stuck in an infinite loop. See
the comment for more explanation.

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

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=130788&r1=130787&r2=130788&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Tue May  3 15:43:02 2011
@@ -2072,12 +2072,6 @@
 bool
 Sema::SetDelegatingInitializer(CXXConstructorDecl *Constructor,
                                CXXCtorInitializer *Initializer) {
-  Constructor->setNumCtorInitializers(1);
-  CXXCtorInitializer **initializer =
-    new (Context) CXXCtorInitializer*[1];
-  memcpy(initializer, &Initializer, sizeof (CXXCtorInitializer*));
-  Constructor->setCtorInitializers(initializer);
-
   // FIXME: This doesn't catch indirect loops yet
   CXXConstructorDecl *Target = Initializer->getTargetConstructor();
   while (Target) {
@@ -2089,6 +2083,18 @@
     Target = Target->getTargetConstructor();
   }
 
+  // We do the cycle detection first so that we know that we're not
+  // going to create a cycle by inserting this link. This ensures that
+  // the AST is cycle-free and we don't get a scenario where we have
+  // a B -> C -> B cycle and then add an A -> B link and get stuck in
+  // an infinite loop as we check for cycles with A and never get there
+  // because we get stuck in a cycle not including A.
+  Constructor->setNumCtorInitializers(1);
+  CXXCtorInitializer **initializer =
+    new (Context) CXXCtorInitializer*[1];
+  memcpy(initializer, &Initializer, sizeof (CXXCtorInitializer*));
+  Constructor->setCtorInitializers(initializer);
+
   return false;
 }
 





More information about the cfe-commits mailing list