Skip to content

Commit 3c46f19

Browse files
akyrtziDougGregor
authored andcommitted
[frontend] Fix use-after-free issue found via ASAN
(cherry picked from commit e6f3af8)
1 parent 4dc5c48 commit 3c46f19

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

lib/Frontend/Frontend.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,4 +638,7 @@ void CompilerInstance::performParseOnly() {
638638
void CompilerInstance::freeContextAndSIL() {
639639
Context.reset();
640640
TheSILModule.reset();
641+
MainModule = nullptr;
642+
SML = nullptr;
643+
PrimarySourceFile = nullptr;
641644
}

lib/FrontendTool/FrontendTool.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -910,10 +910,9 @@ static bool performCompile(CompilerInstance &Instance,
910910
// Free up some compiler resources now that we have an IRModule.
911911
Instance.freeContextAndSIL();
912912

913-
DiagnosticEngine &Diags = Context.Diags;
914913
// Now that we have a single IR Module, hand it over to performLLVM.
915-
return performLLVM(IRGenOpts, &Diags, nullptr, HashGlobal, IRModule.get(),
916-
TargetMachine.get(), EffectiveLanguageVersion,
914+
return performLLVM(IRGenOpts, &Instance.getDiags(), nullptr, HashGlobal,
915+
IRModule.get(), TargetMachine.get(), EffectiveLanguageVersion,
917916
opts.getSingleOutputFilename()) || HadError;
918917
}
919918

0 commit comments

Comments
 (0)