This is an archive of the discontinued LLVM Phabricator instance.

Options: Reduce code duplication
ClosedPublic

Authored by labath on Jun 25 2019, 7:50 AM.

Details

Summary

While investigating breakages caused by D63110, I noticed we were
building the short options strings in three places. Some of them used a
leading ':' to detect missing arguments, and some didn't. This was the
indirect cause of D63110. Here, I move the common code into a utility
function.

Also, unify the code which appends the sentinel value at the end of the
option vector, and make it harder for users to pass invalid argc-argv
combos to getopt (another component of D63110) by having the
OptionParser::Parse function take a (Mutable)ArrayRef.

This unification has uncovered that we don't handle missing arguments
while building aliases, However, it's not possible to write an effective
test for this, as right now it is not possible to return an error out of
the alias parsing code (which means we are printing the generic
"failure" message even after this patch).

Diff Detail

Repository
rL LLVM

Event Timeline

labath created this revision.Jun 25 2019, 7:50 AM
mgorny accepted this revision.Jul 7 2019, 2:57 AM

LGTM.

This revision is now accepted and ready to land.Jul 7 2019, 2:57 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptJul 10 2019, 10:10 AM