diff options
| author | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2014-10-01 18:36:03 +0000 |
|---|---|---|
| committer | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2014-10-01 18:36:03 +0000 |
| commit | 30c9242caad0f82daedb838d73d8311e82b9201b (patch) | |
| tree | df8e941e2ce9e084594f67a817db3d3a02c0e87e /llvm/lib | |
| parent | 847b37ec8aba3bf05db304358bc01beb46b16d17 (diff) | |
| download | bcm5719-llvm-30c9242caad0f82daedb838d73d8311e82b9201b.tar.gz bcm5719-llvm-30c9242caad0f82daedb838d73d8311e82b9201b.zip | |
LTO: Ignore disabled diagnostic remarks
r206400 and r209442 added remarks that are disabled by default.
However, if a diagnostic handler is registered, the remarks are sent
unfiltered to the handler. This is the right behaviour for clang, since
it has its own filters.
However, the diagnostic handler exposed in the LTO API receives only the
severity and message. It doesn't have the information to filter by pass
name. For LTO, disabled remarks should be filtered by the producer.
I've changed `LLVMContext::setDiagnosticHandler()` to take a `bool`
argument indicating whether to respect the built-in filters. This
defaults to `false`, so other consumers don't have a behaviour change,
but `LTOCodeGenerator::setDiagnosticHandler()` sets it to `true`.
To make this behaviour testable, I added a `-use-diagnostic-handler`
command-line option to `llvm-lto`.
This fixes PR21108.
llvm-svn: 218784
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/IR/LLVMContext.cpp | 31 | ||||
| -rw-r--r-- | llvm/lib/IR/LLVMContextImpl.cpp | 1 | ||||
| -rw-r--r-- | llvm/lib/IR/LLVMContextImpl.h | 1 | ||||
| -rw-r--r-- | llvm/lib/LTO/LTOCodeGenerator.cpp | 2 |
4 files changed, 23 insertions, 12 deletions
diff --git a/llvm/lib/IR/LLVMContext.cpp b/llvm/lib/IR/LLVMContext.cpp index d4ba83dfa62..73ddc8cbe20 100644 --- a/llvm/lib/IR/LLVMContext.cpp +++ b/llvm/lib/IR/LLVMContext.cpp @@ -112,9 +112,11 @@ void *LLVMContext::getInlineAsmDiagnosticContext() const { } void LLVMContext::setDiagnosticHandler(DiagnosticHandlerTy DiagnosticHandler, - void *DiagnosticContext) { + void *DiagnosticContext, + bool RespectFilters) { pImpl->DiagnosticHandler = DiagnosticHandler; pImpl->DiagnosticContext = DiagnosticContext; + pImpl->RespectDiagnosticFilters = RespectFilters; } LLVMContext::DiagnosticHandlerTy LLVMContext::getDiagnosticHandler() const { @@ -145,13 +147,7 @@ void LLVMContext::emitError(const Instruction *I, const Twine &ErrorStr) { diagnose(DiagnosticInfoInlineAsm(*I, ErrorStr)); } -void LLVMContext::diagnose(const DiagnosticInfo &DI) { - // If there is a report handler, use it. - if (pImpl->DiagnosticHandler) { - pImpl->DiagnosticHandler(DI, pImpl->DiagnosticContext); - return; - } - +static bool isDiagnosticEnabled(const DiagnosticInfo &DI) { // Optimization remarks are selective. They need to check whether the regexp // pattern, passed via one of the -pass-remarks* flags, matches the name of // the pass that is emitting the diagnostic. If there is no match, ignore the @@ -159,19 +155,32 @@ void LLVMContext::diagnose(const DiagnosticInfo &DI) { switch (DI.getKind()) { case llvm::DK_OptimizationRemark: if (!cast<DiagnosticInfoOptimizationRemark>(DI).isEnabled()) - return; + return false; break; case llvm::DK_OptimizationRemarkMissed: if (!cast<DiagnosticInfoOptimizationRemarkMissed>(DI).isEnabled()) - return; + return false; break; case llvm::DK_OptimizationRemarkAnalysis: if (!cast<DiagnosticInfoOptimizationRemarkAnalysis>(DI).isEnabled()) - return; + return false; break; default: break; } + return true; +} + +void LLVMContext::diagnose(const DiagnosticInfo &DI) { + // If there is a report handler, use it. + if (pImpl->DiagnosticHandler) { + if (!pImpl->RespectDiagnosticFilters || isDiagnosticEnabled(DI)) + pImpl->DiagnosticHandler(DI, pImpl->DiagnosticContext); + return; + } + + if (!isDiagnosticEnabled(DI)) + return; // Otherwise, print the message with a prefix based on the severity. std::string MsgStorage; diff --git a/llvm/lib/IR/LLVMContextImpl.cpp b/llvm/lib/IR/LLVMContextImpl.cpp index 6513965ae7a..09bf6b123a9 100644 --- a/llvm/lib/IR/LLVMContextImpl.cpp +++ b/llvm/lib/IR/LLVMContextImpl.cpp @@ -40,6 +40,7 @@ LLVMContextImpl::LLVMContextImpl(LLVMContext &C) InlineAsmDiagContext = nullptr; DiagnosticHandler = nullptr; DiagnosticContext = nullptr; + RespectDiagnosticFilters = false; YieldCallback = nullptr; YieldOpaqueHandle = nullptr; NamedStructTypesUniqueID = 0; diff --git a/llvm/lib/IR/LLVMContextImpl.h b/llvm/lib/IR/LLVMContextImpl.h index b376064d2ed..bd0097c31ba 100644 --- a/llvm/lib/IR/LLVMContextImpl.h +++ b/llvm/lib/IR/LLVMContextImpl.h @@ -244,6 +244,7 @@ public: LLVMContext::DiagnosticHandlerTy DiagnosticHandler; void *DiagnosticContext; + bool RespectDiagnosticFilters; LLVMContext::YieldCallbackTy YieldCallback; void *YieldOpaqueHandle; diff --git a/llvm/lib/LTO/LTOCodeGenerator.cpp b/llvm/lib/LTO/LTOCodeGenerator.cpp index 1b6f905f0ac..75ca56fbbe7 100644 --- a/llvm/lib/LTO/LTOCodeGenerator.cpp +++ b/llvm/lib/LTO/LTOCodeGenerator.cpp @@ -558,5 +558,5 @@ LTOCodeGenerator::setDiagnosticHandler(lto_diagnostic_handler_t DiagHandler, return Context.setDiagnosticHandler(nullptr, nullptr); // Register the LTOCodeGenerator stub in the LLVMContext to forward the // diagnostic to the external DiagHandler. - Context.setDiagnosticHandler(LTOCodeGenerator::DiagnosticHandler, this); + Context.setDiagnosticHandler(LTOCodeGenerator::DiagnosticHandler, this, true); } |

