This revision was landed with ongoing or failed builds. This revision was automatically updated to reflect the committed changes. Closed by commit rGe54811ff7e0b: Restore diagnostic handler after CodeGenAction::ExecuteAction (authored by mantognini).
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D96487/new/ https://reviews.llvm.org/D96487 Files: clang/lib/CodeGen/CodeGenAction.cpp llvm/include/llvm/IR/LLVMContext.h Index: llvm/include/llvm/IR/LLVMContext.h =================================================================== --- llvm/include/llvm/IR/LLVMContext.h +++ llvm/include/llvm/IR/LLVMContext.h @@ -190,10 +190,11 @@ DiagnosticHandler::DiagnosticHandlerTy DiagHandler, void *DiagContext = nullptr, bool RespectFilters = false); - /// setDiagnosticHandler - This method sets unique_ptr to object of DiagnosticHandler - /// to provide custom diagnostic handling. The first argument is unique_ptr of object - /// of type DiagnosticHandler or a derived of that. The third argument should be - /// set to true if the handler only expects enabled diagnostics. + /// setDiagnosticHandler - This method sets unique_ptr to object of + /// DiagnosticHandler to provide custom diagnostic handling. The first + /// argument is unique_ptr of object of type DiagnosticHandler or a derived + /// of that. The second argument should be set to true if the handler only + /// expects enabled diagnostics. /// /// Ownership of this pointer is moved to LLVMContextImpl. void setDiagnosticHandler(std::unique_ptr<DiagnosticHandler> &&DH, @@ -211,7 +212,7 @@ /// setDiagnosticHandler. const DiagnosticHandler *getDiagHandlerPtr() const; - /// getDiagnosticHandler - transfers owenership of DiagnosticHandler unique_ptr + /// getDiagnosticHandler - transfers ownership of DiagnosticHandler unique_ptr /// to caller. std::unique_ptr<DiagnosticHandler> getDiagnosticHandler(); Index: clang/lib/CodeGen/CodeGenAction.cpp =================================================================== --- clang/lib/CodeGen/CodeGenAction.cpp +++ clang/lib/CodeGen/CodeGenAction.cpp @@ -1115,6 +1115,14 @@ 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(),
Index: llvm/include/llvm/IR/LLVMContext.h =================================================================== --- llvm/include/llvm/IR/LLVMContext.h +++ llvm/include/llvm/IR/LLVMContext.h @@ -190,10 +190,11 @@ DiagnosticHandler::DiagnosticHandlerTy DiagHandler, void *DiagContext = nullptr, bool RespectFilters = false); - /// setDiagnosticHandler - This method sets unique_ptr to object of DiagnosticHandler - /// to provide custom diagnostic handling. The first argument is unique_ptr of object - /// of type DiagnosticHandler or a derived of that. The third argument should be - /// set to true if the handler only expects enabled diagnostics. + /// setDiagnosticHandler - This method sets unique_ptr to object of + /// DiagnosticHandler to provide custom diagnostic handling. The first + /// argument is unique_ptr of object of type DiagnosticHandler or a derived + /// of that. The second argument should be set to true if the handler only + /// expects enabled diagnostics. /// /// Ownership of this pointer is moved to LLVMContextImpl. void setDiagnosticHandler(std::unique_ptr<DiagnosticHandler> &&DH, @@ -211,7 +212,7 @@ /// setDiagnosticHandler. const DiagnosticHandler *getDiagHandlerPtr() const; - /// getDiagnosticHandler - transfers owenership of DiagnosticHandler unique_ptr + /// getDiagnosticHandler - transfers ownership of DiagnosticHandler unique_ptr /// to caller. std::unique_ptr<DiagnosticHandler> getDiagnosticHandler(); Index: clang/lib/CodeGen/CodeGenAction.cpp =================================================================== --- clang/lib/CodeGen/CodeGenAction.cpp +++ clang/lib/CodeGen/CodeGenAction.cpp @@ -1115,6 +1115,14 @@ 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(),
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits