@@ -189,6 +189,8 @@ namespace {
189
189
TUState (*static_cast <SILParserState *>(P.SIL)),
190
190
ParsedTypeCallback([](Type ty) {}) {}
191
191
192
+ ~SILParser ();
193
+
192
194
// / diagnoseProblems - After a function is fully parse, emit any diagnostics
193
195
// / for errors and return true if there were any.
194
196
bool diagnoseProblems ();
@@ -516,6 +518,17 @@ bool SILParser::parseVerbatim(StringRef name) {
516
518
return false ;
517
519
}
518
520
521
+ SILParser::~SILParser () {
522
+ for (auto &Entry : ForwardRefLocalValues) {
523
+ if (ValueBase *dummyVal = LocalValues[Entry.first ()]) {
524
+ dummyVal->replaceAllUsesWith (SILUndef::get (dummyVal->getType (), SILMod, ValueOwnershipKind::None));
525
+ SILInstruction::destroy (cast<GlobalAddrInst>(dummyVal));
526
+ SILMod.deallocateInst (cast<GlobalAddrInst>(dummyVal));
527
+ }
528
+ }
529
+ }
530
+
531
+
519
532
// / diagnoseProblems - After a function is fully parse, emit any diagnostics
520
533
// / for errors and return true if there were any.
521
534
bool SILParser::diagnoseProblems () {
@@ -686,7 +699,7 @@ SILValue SILParser::getLocalValue(UnresolvedValueName Name, SILType Type,
686
699
P.diagnose (Name.NameLoc , diag::sil_value_use_type_mismatch, Name.Name ,
687
700
EntryTy.getASTType (), Type.getASTType ());
688
701
// Make sure to return something of the requested type.
689
- return new (SILMod) GlobalAddrInst ( getDebugLoc (B, Loc), Type );
702
+ return SILUndef::get (Type, B. getFunction () );
690
703
}
691
704
692
705
return SILValue (Entry);
@@ -724,6 +737,8 @@ void SILParser::setLocalValue(ValueBase *Value, StringRef Name,
724
737
} else {
725
738
// Forward references only live here if they have a single result.
726
739
Entry->replaceAllUsesWith (Value);
740
+ SILInstruction::destroy (cast<GlobalAddrInst>(Entry));
741
+ SILMod.deallocateInst (cast<GlobalAddrInst>(Entry));
727
742
}
728
743
Entry = Value;
729
744
return ;
0 commit comments