diff --git a/gcc/et-forest.c b/gcc/et-forest.c
index c15b6d8..94757c0 100644
--- a/gcc/et-forest.c
+++ b/gcc/et-forest.c
@@ -661,7 +661,7 @@ et_nca (struct et_node *n1, struct et_node *n2)
       if (r)
 	r->parent = o1;
     }
-  else
+  else if (r == o2 || (r && r->parent != NULL))
     {
       ret = o2->prev;
 
@@ -669,6 +669,15 @@ et_nca (struct et_node *n1, struct et_node *n2)
       if (l)
 	l->parent = o1;
     }
+  else
+    {
+      /* O1 and O2 are in different components of the forest.  */
+      if (l)
+	l->parent = o1;
+      if (r)
+	r->parent = o1;
+      return NULL;
+    }
 
   if (0 < o2->depth)
     {
