This is an archive of the discontinued LLVM Phabricator instance.

Switch to consumeError(), since this can crash otherwise.
ClosedPublic

Authored by srhines on Aug 14 2017, 8:59 PM.

Details

Summary

If assertions are disabled, but LLVM_ABI_BREAKING_CHANGES is enabled,
this will cause an issue with an unchecked Success. Switching to
consumeError() is the correct way to bypass the check.

Diff Detail

Repository
rL LLVM

Event Timeline

srhines created this revision.Aug 14 2017, 8:59 PM

https://reviews.llvm.org/D36729 similarly fixes a few more instances of this problem (discovered while running tests for this configuration).

arphaman accepted this revision.Aug 14 2017, 11:54 PM
arphaman added a subscriber: arphaman.

LGTM

This revision is now accepted and ready to land.Aug 14 2017, 11:54 PM
This revision was automatically updated to reflect the committed changes.
lhames added a subscriber: lhames.Aug 15 2017, 2:27 PM

The preferred solution to this is actually to wrap the call with cantFail (See http://llvm.org/docs/ProgrammersManual.html#using-cantfail-to-simplify-safe-callsites) -- it will handle both the assertion and consumption of the value for you, and will simplify calls that return an Expected<T>.

The preferred solution to this is actually to wrap the call with cantFail (See http://llvm.org/docs/ProgrammersManual.html#using-cantfail-to-simplify-safe-callsites) -- it will handle both the assertion and consumption of the value for you, and will simplify calls that return an Expected<T>.

Is it ok to drop the assertion in that case (and convert it to a comment)? I didn't want to alter too much of this check, since perhaps the original author(s) were more skeptical about this breaking (hence the assertion). Something like:

// Replacements must not conflict since ranges have been merged.
llvm::cantFail(FakeReplaces.add(...));

Is it ok to drop the assertion in that case (and convert it to a comment)? I didn't want to alter too much of this check, since perhaps the original author(s) were more skeptical about this breaking (hence the assertion). Something like:

// Replacements must not conflict since ranges have been merged.
llvm::cantFail(FakeReplaces.add(...));

Yep - cantFail asserts that the result is success, so your proposed change (with the assertion text above the call) is ideal.

https://reviews.llvm.org/D36806 switches this to cantFail(). Thanks for helping me better understand LLVM's error strategy.