[PATCH] Add diagnostic capabilities in LLVM (frontend part)

Quentin Colombet qcolombet at apple.com
Tue Dec 17 11:22:55 PST 2013


Hi,

Here is a patch that propagates the backend diagnostics into the frontend diagnostics.

** Context **

In r197508, we added in the LLVMContext a diagnostic handler hook to report errors, warnings, and notes that are issued by the backend (http://llvm-reviews.chandlerc.com/D2376).

Currently, there are three kind of diagnostic:
- Inline asm: The existing inline asm errors, that have been extended to warnings and notes.
- Stack size: The existing backend warning that used to wildly print on stderr a warning when the stack size exceeds a given size.
- Plugin: A generic kind that allows arbitrary diagnostic reporting.


** Overall Design **

With this new hook, the backend passes the diagnostic information via DiagnosticInfo class.
The base class gives two basic information:
- The severity.
- The kind.

Based on these information  (Severity, Kind), the frontend can decide to either:
- Use the related sub class (identify by Kind) and build its own diagnostic.
or
- Use the default print method that is a fall back in case the frontend does not know how to deal with this specific diagnostic.
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.


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. 


** Proposed Patch **

- Add a diagnostic handler matching the new hook in BackendConsumer (BackendConsumer::DiagnosticHandler).
- Register this handler in the LLVMContext.
- Add a new frontend diagnostic kind (backend-<kind>) for each backend kind (inline-asm, stack-size, plugin).
- Format and propagate the backend diagnostics to the newly added frontend diagnostics (BackendConsumer::InlineAsmDiagHandler and BackendConsumer::StackSizeHandler).
- Fall back to the print method for plugin diagnostics (as part of BackendConsumer::DiagnosticHandler2).


** What Is Missing? **

- Dedicated DiagnosticPrinter.
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.

- Demangling of function name.
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.

- Warning with argument.
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.
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).

- Tests.
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?

Thanks for your feedbacks.

Cheers,
-Quentin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20131217/f0b966bf/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: BackendDiagnostic.patch
Type: application/octet-stream
Size: 8239 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20131217/f0b966bf/attachment.obj>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20131217/f0b966bf/attachment-0001.html>


More information about the cfe-commits mailing list