[llvm] obj2yaml/COFF: improve reporting of fatal errors (PR #87652)
James Henderson via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 5 00:24:53 PDT 2024
https://github.com/jh7370 requested changes to this pull request.
This isn't the right way to handle errors: `report_fatal_error` is not much better than an `assert` or crash. Instead, you should really bubble the error up to the layer in the tool that reports errors using the tool's own reporting mechanism (in this case, see https://github.com/llvm/llvm-project/blob/840b21f63d233d8b982aed5fb52f614da565538d/llvm/tools/obj2yaml/obj2yaml.cpp#L91). It might be informative to take a look at how elf2yaml does this, for example, since this code is used by a constructor and therefore the error can't simply be returned using `return`.
Also, you need a test case really. To test this, you'll need to use a tool to generate the invalid file, probably yaml2obj, which in turn may need modifying in some way to make it possible to generate the invalid output (yaml2obj is designed in part to allow creation of invalid output for testing).
https://github.com/llvm/llvm-project/pull/87652
More information about the llvm-commits
mailing list