<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">Hi,<div><br></div><div>Here is a patch that propagates the backend diagnostics into the frontend diagnostics.</div><div><br></div><div>** Context **</div><div><br></div><div>In r197508, we added in the LLVMContext a diagnostic handler hook to report errors, warnings, and notes that are issued by the backend (<a href="http://llvm-reviews.chandlerc.com/D2376">http://llvm-reviews.chandlerc.com/D2376</a>).</div><div><br></div><div>Currently, there are three kind of diagnostic:</div><div>- Inline asm: The existing inline asm errors, that have been extended to warnings and notes.</div><div>- Stack size: The existing backend warning that used to wildly print on stderr a warning when the stack size exceeds a given size.</div><div>- Plugin: A generic kind that allows arbitrary diagnostic reporting.</div><div><br></div><div><br></div><div>** Overall Design **</div><div><br></div><div>With this new hook, the backend passes the diagnostic information via DiagnosticInfo class.</div><div>The base class gives two basic information:</div><div>- The severity.</div><div>- The kind.</div><div><br></div><div>Based on these information  (Severity, Kind), the frontend can decide to either:</div><div>- Use the related sub class (identify by Kind) and build its own diagnostic.</div><div>or</div><div>- Use the default print method that is a fall back in case the frontend does not know how to deal with this specific diagnostic.</div><div>The print method takes a DiagnosticPrinter class as argument. This helper class can be tuned in the frontend to format appropriately some important cases. A default implementation using raw_ostream is available.</div><div><br></div><div><br></div><div>Note: Backend diagnostics are supposed to be rarely added. Thus, the patch does not feature any support for adding a new backend diagnostic. This  remains a manual task. </div><div><br></div><div><br></div><div>** Proposed Patch **</div><div><br></div><div>- Add a diagnostic handler matching the new hook in BackendConsumer (BackendConsumer::DiagnosticHandler).</div><div>- Register this handler in the LLVMContext.</div><div>- Add a new frontend diagnostic kind (backend-<kind>) for each backend kind (inline-asm, stack-size, plugin).</div><div>- Format and propagate the backend diagnostics to the newly added frontend diagnostics (BackendConsumer::InlineAsmDiagHandler and BackendConsumer::StackSizeHandler).</div><div>- Fall back to the print method for plugin diagnostics (as part of BackendConsumer::DiagnosticHandler2).</div><div><br></div><div><br></div><div>** What Is Missing? **</div><div><br></div><div>- Dedicated DiagnosticPrinter.</div><div>This patch does not roll a dedicated DiagnosticPrinter. I thought a frontend guy may be better suited for this task if we want to supply this support.</div><div><br></div><div>- Demangling of function name.</div><div>It would be nice to demangle the function name as illustrated by the fix-me in BackendConsumer::StackSizeHandler. I have not idea how I should do that.</div><div><br></div><div>- Warning with argument.</div><div>The stack size warning requires that we specify the limit that will trigger the diagnostic. Currently, this limit is still set using -llvm -warn-stack-size=<limit>. As far as I know, we do not have a way to specify an option to a warning, e.g., -WmyWarning=<limit>. Therefore, this weirdness is not corrected by this patch.</div><div>The bottom line is, to turn a stack size warning into an error, one has to set -mlvm -warn-stack-size=<limit> -Werror=backend-stack-size (or -Werror).</div><div><br></div><div>- Tests.</div><div>I made some tests locally, but the patch does not add any test case. The question is how can we add tests that require both a backend and a frontend in either the frontend or the backend?</div><div><br></div><div>Thanks for your feedbacks.</div><div><br></div><div>Cheers,<br><div apple-content-edited="true">
<div style="color: rgb(0, 0, 0); font-family: Helvetica;  font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">-Quentin</div>

</div>
</div></body></html>