@@ -367,10 +367,13 @@ RequirementMachine *RewriteContext::getRequirementMachine(
367367 // Store this requirement machine before adding the signature,
368368 // to catch re-entrant construction via initWithGenericSignature()
369369 // below.
370- machine = new rewriting::RequirementMachine (*this );
371- machine-> initWithGenericSignature (sig) ;
370+ auto *newMachine = new rewriting::RequirementMachine (*this );
371+ machine = newMachine ;
372372
373- return machine;
373+ // This might re-entrantly invalidate 'machine', which is a reference
374+ // into Protos.
375+ newMachine->initWithGenericSignature (sig);
376+ return newMachine;
374377}
375378
376379bool RewriteContext::isRecursivelyConstructingRequirementMachine (
@@ -484,14 +487,19 @@ RequirementMachine *RewriteContext::getRequirementMachine(
484487 llvm::errs () << " " << proto->getName ();
485488 abort ();
486489 }
487- } else {
488- // Construct a requirement machine from the structural requirements of
489- // the given set of protocols.
490- machine = new RequirementMachine (*this );
491- machine->initWithProtocols (component.Protos );
490+
491+ return machine;
492492 }
493493
494- return machine;
494+ // Construct a requirement machine from the structural requirements of
495+ // the given set of protocols.
496+ auto *newMachine = new RequirementMachine (*this );
497+ machine = newMachine;
498+
499+ // This might re-entrantly invalidate 'machine', which is a reference
500+ // into Protos.
501+ newMachine->initWithProtocols (component.Protos );
502+ return newMachine;
495503}
496504
497505// / We print stats in the destructor, which should get executed at the end of
0 commit comments