aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/SemaDeclCXX.cpp
diff options
context:
space:
mode:
authorSean Hunt <scshunt@csclub.uwaterloo.ca>2011-05-03 20:43:02 +0000
committerSean Hunt <scshunt@csclub.uwaterloo.ca>2011-05-03 20:43:02 +0000
commit01aacc024673e84181ae687ff1c65ab65e10571a (patch)
treef706e75a40eea2e4a8e94b06f478cbb0bcd45c1e /lib/Sema/SemaDeclCXX.cpp
parent06bc9eb9908e42696775b395b290827bde468c8b (diff)
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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@130788 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaDeclCXX.cpp')
-rw-r--r--lib/Sema/SemaDeclCXX.cpp18
1 files changed, 12 insertions, 6 deletions
diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp
index 27632a1a57..94177b1d12 100644
--- a/lib/Sema/SemaDeclCXX.cpp
+++ b/lib/Sema/SemaDeclCXX.cpp
@@ -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;
}