This is an archive of the discontinued LLVM Phabricator instance.

Fix a bunch of assert-on-invalid-bitcode regressions after 315483
ClosedPublic

Authored by thakis on Oct 30 2017, 3:28 PM.

Details

Reviewers
rafael
thakis
Summary

Expected<> calls assertIsChecked() in its dtor, and operator bool() only calls setChecked() if there's no error. So for functions that don't return an error itself, the Expected<> version needs explicit code to disarm the error that the ErrorOr<> code didn't need.

I didn't audit other revisions that converted ErrorOr<> to Expected<>, there are possibly more changes like this needed.

This fixes an assert from libLTO.dylib while linking chrome/iOS.

Diff Detail

Event Timeline

thakis created this revision.Oct 30 2017, 3:28 PM
thakis added inline comments.Oct 30 2017, 3:30 PM
lib/LTO/LTOModule.cpp
80–84

...I'll come in again.

thakis updated this revision to Diff 120903.Oct 30 2017, 3:31 PM

fix copy-pasto

thakis marked an inline comment as done.Oct 30 2017, 3:31 PM

rL315477, rL315475, rL315474, rL315473, rL315376, rL315354 seem to not have introduced bugs of this type as far as I can tell.

thakis updated this revision to Diff 120987.Oct 31 2017, 8:41 AM

Now with test (only for one of the 4 changes, but the one we hit in practice. I don't see how to test the other 3). Feeling pretty good about this now.

thakis updated this revision to Diff 120997.Oct 31 2017, 9:38 AM

Now with better test. I'm going to land this; happy to address post-commit review comments of course.

thakis accepted this revision.Oct 31 2017, 9:40 AM

317010

This revision is now accepted and ready to land.Oct 31 2017, 9:40 AM
thakis closed this revision.Oct 31 2017, 9:40 AM

I'm not subscribed to llvm-commits so replying here:

What happened to the errorToBool idea?

Apologies I didn't see that suggestion (it's here: http://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20171030/498706.html) because it didn't make it to phab somehow. (Weren't email replies supposed to show up on phab?)

errorToErrorCode() takes an error. The new function here would take an Expected, right? Do you want

return expectedToBool(BCData);

in the first two functions? If so, that wouldn't make the 3rd any shorter. If we had an errorToBool(), the first three would look like

if (!BCData)
  return errorToBool(BCData.takeError());

(followed by

return true;

in the first two.)

None of these would help with the 4th question. Which one do you want? To me it's not obvious which one will pan out best, so it feels a bit like premature abstraction to me. But happy to implement whatever you want, I just don't understand what it is yet.

It could be just

errorToBool(BCData.takeError());

and errorToBool() can handle ErrorSuccess, no?

Ah! And then errorToBool() would return true for error or for non-error? I.e. should isBitcodeFile() end in

return errorToBool(BCData.takeError());

or

return !errorToBool(BCData.takeError());

It's not clear to me from the name errorToBool() if true should mean "all good" or "it's an error". The name sounds like the latter, but then all of its current callers will return its result negated.