Page MenuHomePhabricator

[Error] Add source location to cantFail
Needs ReviewPublic

Authored by hintonda on Nov 14 2019, 11:05 AM.

Details

Reviewers
lhames
beanz
Summary

Add llvm_cantFail macro, a drop in replacement for llvm::cantFail,
that adds source location, similar to assert, for !NDEBUG builds.

Refactor to extract error handling code and place it and new annotated
versions of cantFail that are called by the new macro in a detail
namespace, and change all instances in llvm to use the new macro.

Event Timeline

hintonda created this revision.Nov 14 2019, 11:05 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 14 2019, 11:05 AM
hintonda updated this revision to Diff 229381.Nov 14 2019, 12:51 PM
  • Replace macro magic with matching 3-parameter template functions.

Hi Don,

This is a great idea!

I think it would actually be reasonable to have 'cantFail' be the macro though, and move the existing functions (which become an implementation detail) into a detail namespace: We want cantFail to be succinct as part of its value is clarifying flow when we know (from the surrounding context) that errors will not be generated.

hintonda updated this revision to Diff 230125.Nov 19 2019, 12:25 PM
  • Replace macro magic with matching 3-parameter template functions.
  • Refactor cantFail move into detail namespace. Change macro name to
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptNov 19 2019, 12:25 PM
hintonda updated this revision to Diff 230131.Nov 19 2019, 12:43 PM
  • Add back original llvm::cantFail signatures so they'll still be
hintonda updated this revision to Diff 230140.Nov 19 2019, 1:41 PM

Append "_annotated" suffix to detail functions.
Add "llvm_" prefix to macros.
Revert changes to all non-llvm project files.
Update calls in llvm to use new macro.

hintonda edited the summary of this revision. (Show Details)Nov 19 2019, 1:49 PM
hintonda removed projects: Restricted Project, Restricted Project.
hintonda removed subscribers: cfe-commits, lldb-commits.

@lhames, I think I've applied all your verbal changes, but please let me
know if I missed anything.

Essentially, previous behavior is maintained, but users can opt-in to the
new behavior, adding file and line numbers, by switching to the new macro.
I also updated all of llvm, but excluded other projects for the time being.
Most of them use llvm::cantFail, and could be updated as needed via a
script, e.g., something like this would do it:

find clang -type f \( -name "*.cpp" -o -name "*.h" \) -exec grep -l "cantFail" \{\} \; | xargs sed -i.bak 's/llvm::cantFail/llvm_cantFail/'