This is an archive of the discontinued LLVM Phabricator instance.

[pdb] Fix errors with invalid stream numbers
ClosedPublic

Authored by zturner on Jun 8 2016, 6:07 AM.

Details

Summary

This should fix most, if not all of the llvm-pdbdump-fuzzer errors. The problem is that we were not always checking that stream numbers were valid. This fixes that by making the constructor to MappedBlockStream private and only exposing it through a static creator which returns an Expected<unique_ptr<MappedBlockStream>>.

One problem that came up is that it's getting pretty ugly to write 4-5 lines of code to check an Expected<T> and return the error every time. I had the idea to wrap this up in some macros, but unfortunately it didn't go very well. You can see the results here. I could not find a way to do it without 6 different macros. If anyone can think of a way to make this less onerous, I'm all ears. Requirements:

  1. It should work if you have a failed Expected<T> and on error you return a failed Expected<U>, where T != U.
  2. It should work if you have a failed Expected<T> and you are returning an llvm::Error.
  3. It should work if T is a reference type, such as Expected<DbiStream&>.
  4. It should work if T is not copyable, such as Expected<std::unique_ptr<MappedBlockStream>>.
  5. It should work if you want the "success" value to go into an existing variable (such as a class member variable)
  6. It should work if you don't have a success variable declared and you want the macro to auto-declare it.

Diff Detail

Event Timeline

zturner updated this revision to Diff 60020.Jun 8 2016, 6:07 AM
zturner retitled this revision from to [pdb] Fix errors with invalid stream numbers.
zturner updated this object.
zturner added reviewers: majnemer, rnk, ruiu.
zturner added a subscriber: llvm-commits.
ruiu edited edge metadata.Jun 8 2016, 8:05 AM

I think I honestly don't like these macros. They indeed reduces amount of code but are hard to read. I prefer the current style (explicitly writing control flow in a plain C++) over the magical macros.

zturner added a subscriber: zturner.Jun 8 2016, 8:19 AM

Is it because there are so many? Or for a different reason? There was one
case where there were like 15 lines of code jsut to get all the values out
of the functions and do the error checking, I found it really hurt the
ability to read the code.

I do agree that there are too many though. I'm not a C++ wizard, but if
someone can help me figure out how to write them with fewer macros, do you
think that would be better?

I actually I just thought of a better way. I will try it later when I get
in.

zturner updated this revision to Diff 60061.Jun 8 2016, 10:14 AM
zturner edited edge metadata.

Remove macros, resort to manual error checking.

ruiu accepted this revision.Jun 8 2016, 10:20 AM
ruiu edited edge metadata.

LGTM

This revision is now accepted and ready to land.Jun 8 2016, 10:20 AM
This revision was automatically updated to reflect the committed changes.