aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CodeGenAction.cpp
diff options
context:
space:
mode:
authorMarco Antognini <marco.antognini@arm.com>2021-02-08 18:14:22 +0000
committerMarco Antognini <marco.antognini@arm.com>2021-02-15 10:33:00 +0000
commite54811ff7e0bc99f337bcbb569311bb166187322 (patch)
treea75b9b89723b34a5466c0a7c837fbe041883dbfd /clang/lib/CodeGen/CodeGenAction.cpp
parentc70737ba1dea947350879a4f53a4a5513d6c9252 (diff)
downloadllvm-e54811ff7e0bc99f337bcbb569311bb166187322.zip
llvm-e54811ff7e0bc99f337bcbb569311bb166187322.tar.gz
llvm-e54811ff7e0bc99f337bcbb569311bb166187322.tar.bz2
Restore diagnostic handler after CodeGenAction::ExecuteAction
Fix dangling pointer to local variable and address some typos. Reviewed By: xur Differential Revision: https://reviews.llvm.org/D96487
Diffstat (limited to 'clang/lib/CodeGen/CodeGenAction.cpp')
-rw-r--r--clang/lib/CodeGen/CodeGenAction.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/CodeGenAction.cpp b/clang/lib/CodeGen/CodeGenAction.cpp
index 778d4df..da35246 100644
--- a/clang/lib/CodeGen/CodeGenAction.cpp
+++ b/clang/lib/CodeGen/CodeGenAction.cpp
@@ -1115,6 +1115,14 @@ void CodeGenAction::ExecuteAction() {
LLVMContext &Ctx = TheModule->getContext();
Ctx.setInlineAsmDiagnosticHandler(BitcodeInlineAsmDiagHandler, &Diagnostics);
+ // Restore any diagnostic handler previously set before returning from this
+ // function.
+ struct RAII {
+ LLVMContext &Ctx;
+ std::unique_ptr<DiagnosticHandler> PrevHandler = Ctx.getDiagnosticHandler();
+ ~RAII() { Ctx.setDiagnosticHandler(std::move(PrevHandler)); }
+ } _{Ctx};
+
// Set clang diagnostic handler. To do this we need to create a fake
// BackendConsumer.
BackendConsumer Result(BA, CI.getDiagnostics(), CI.getHeaderSearchOpts(),