]> granicus.if.org Git - clang/commitdiff
Move the AST modifications to after the cycle detection in
authorSean Hunt <scshunt@csclub.uwaterloo.ca>
Tue, 3 May 2011 20:43:02 +0000 (20:43 +0000)
committerSean Hunt <scshunt@csclub.uwaterloo.ca>
Tue, 3 May 2011 20:43:02 +0000 (20:43 +0000)
lib/Sema/SemaDeclCXX.cpp to avoid getting stuck in an infinite loop. See
the comment for more explanation.

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

lib/Sema/SemaDeclCXX.cpp

index 27632a1a57c452f02a501068ade631f28b8ef7f1..94177b1d127d53c2b4ee34275f515537482903ba 100644 (file)
@@ -2072,12 +2072,6 @@ static bool CollectFieldInitializer(BaseAndFieldInfo &Info,
 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 @@ Sema::SetDelegatingInitializer(CXXConstructorDecl *Constructor,
     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;
 }