Skip to content

Commit 7182440

Browse files
committedAug 18, 2017
Give guidance on report_fatal_error in CodingStandards.rst and ProgrammersManual.rst
The current ProgrammersManual.rst document has a lot of well-written documentation on error handling thanks to @lhames. It suggests errors can be split cleanly into "programmatic" and "recoverable" errors. However, the reality in current LLVM seems to be there are a number of cases where a non-programmatic error is not easily recoverable. Therefore, add a note to indicate the existence of report_fatal_error for these cases. I've also added a reminder to CodingStandards.rst in the section on assertions, to indicate that llvm_unreachable and assertions should not be relied upon to report errors triggered by user input. The ProgrammersManual is also silent on the use of LLVMContext::diagnose, which is used in BPF+WebAssembly+AMDGPU to report some errors during instruction selection. I don't address that in this patch, as it's not quite clear how to fit in to the current error handling story Differential Revision: https://reviews.llvm.org/D36826 llvm-svn: 311146
1 parent 7eaaa0f commit 7182440

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed
 

‎llvm/docs/CodingStandards.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,6 +1232,11 @@ builds), ``llvm_unreachable`` becomes a hint to compilers to skip generating
12321232
code for this branch. If the compiler does not support this, it will fall back
12331233
to the "abort" implementation.
12341234

1235+
Neither assertions or ``llvm_unreachable`` will abort the program on a release
1236+
build. If the error condition can be triggered by user input, then the
1237+
recoverable error mechanism described in :doc:`ProgrammersManual` or
1238+
``report_fatal_error`` should be used instead.
1239+
12351240
Another issue is that values used only by assertions will produce an "unused
12361241
value" warning when assertions are disabled. For example, this code will warn:
12371242

‎llvm/docs/ProgrammersManual.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,14 @@ the program where they can be handled appropriately. Handling the error may be
441441
as simple as reporting the issue to the user, or it may involve attempts at
442442
recovery.
443443

444+
.. note::
445+
446+
Ideally, the error handling approach described in this section would be
447+
used throughout LLVM. However, this is not yet the case. For
448+
non-programmatic errors where the ``Error`` scheme cannot easily be
449+
applied, ``report_fatal_error`` should be used to call any installed error
450+
handler and then terminate the program.
451+
444452
Recoverable errors are modeled using LLVM's ``Error`` scheme. This scheme
445453
represents errors using function return values, similar to classic C integer
446454
error codes, or C++'s ``std::error_code``. However, the ``Error`` class is

0 commit comments

Comments
 (0)
Please sign in to comment.