This is an archive of the discontinued LLVM Phabricator instance.

[OptTable] Improve error message output for grouped short options
ClosedPublic

Authored by gbreynoo on Aug 26 2021, 9:03 AM.

Details

Summary

As seen in https://bugs.llvm.org/show_bug.cgi?id=48880 the current implementation for parsing grouped short options can return unclear error messages.

This change fixes the example given in the ticket in which a flag is incorrectly given an argument. Also when parsing a group we now keep reading past the first incorrect option and output errors for all incorrect options in the group.

This change includes additional test cases added to llvm-symbolizer/unknown-argument.test and fixes up llvm-objcopy/tool-help-message.test due to the change in error output. Note that due to implementation of llvm-objcopy only the first incorrect argument is output.

Diff Detail

Event Timeline

gbreynoo created this revision.Aug 26 2021, 9:03 AM
gbreynoo requested review of this revision.Aug 26 2021, 9:03 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 26 2021, 9:03 AM
gbreynoo added inline comments.Aug 26 2021, 9:05 AM
llvm/lib/Option/OptTable.cpp
379–383

I could not find a case in which we would enter if (Str.size() == 2) so I have removed it. I think either the option would have already been accepted or we want to create the an Arg as unknown option.

The main test should be moved from llvm-symbolizer to llvm/unittests/Option/OptionParsingTest.cpp

MaskRay added inline comments.Aug 26 2021, 10:29 AM
llvm/lib/Option/OptTable.cpp
379–383

This is ok

jhenderson added inline comments.Aug 27 2021, 12:09 AM
llvm/lib/Option/OptTable.cpp
379–383
389
gbreynoo updated this revision to Diff 369104.Aug 27 2021, 8:11 AM

Fixed comments as suggested by Jhenderson and moved the llvm-symbolizer/unknown-argument.test changes to unit tests as suggested by MaskRay.

gbreynoo marked 3 inline comments as done.Aug 27 2021, 8:12 AM
MaskRay accepted this revision.Aug 27 2021, 8:41 AM

LGTM.

This revision is now accepted and ready to land.Aug 27 2021, 8:41 AM
kda added a subscriber: kda.Aug 31 2021, 1:57 PM

This looks like it broke the sanitizer build blocks.
https://lab.llvm.org/buildbot/#/builders/5/builds/11210

A guide to reproducing sanitizer bots can be found here: https://github.com/google/sanitizers/wiki/SanitizerBotReproduceBuild

relevant log snippet below:

FAIL: LLVM-Unit :: Option/./OptionTests/Option.FlagsWithoutValues (73786 of 78710)
******************** TEST 'LLVM-Unit :: Option/./OptionTests/Option.FlagsWithoutValues' FAILED ********************
Script:
--
/b/sanitizer-x86_64-linux-fast/build/llvm_build_asan/unittests/Option/./OptionTests --gtest_filter=Option.FlagsWithoutValues
--
Note: Google Test filter = Option.FlagsWithoutValues
[==========] Running 1 test from 1 test suite.
[----------] Global test environment set-up.
[----------] 1 test from Option
[ RUN      ] Option.FlagsWithoutValues
[       OK ] Option.FlagsWithoutValues (0 ms)
[----------] 1 test from Option (0 ms total)
[----------] Global test environment tear-down
[==========] 1 test from 1 test suite ran. (1 ms total)
[  PASSED  ] 1 test.
=================================================================
==28024==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 176 byte(s) in 2 object(s) allocated from:
    #0 0x37e7fd in operator new(unsigned long) /b/s/w/ir/cache/builder/src/third_party/llvm/compiler-rt/lib/asan/asan_new_delete.cpp:95:3
    #1 0x3c88e6 in llvm::opt::Option::accept(llvm::opt::ArgList const&, llvm::StringRef, bool, unsigned int&) const /b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/lib/Option/Option.cpp:236:32
    #2 0x3cd195 in llvm::opt::OptTable::parseOneArgGrouped(llvm::opt::InputArgList&, unsigned int&) const /b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/lib/Option/OptTable.cpp:378:22
    #3 0x3cf4f2 in llvm::opt::OptTable::ParseArgs(llvm::ArrayRef<char const*>, unsigned int&, unsigned int&, unsigned int, unsigned int) const /b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/lib/Option/OptTable.cpp:485:20
    #4 0x3a8ce0 in Option_FlagsWithoutValues_Test::TestBody() /b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/unittests/Option/OptionParsingTest.cpp:385:23
    #5 0x4d60db in HandleExceptionsInMethodIfSupported<testing::Test, void> /b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/unittest/googletest/src/gtest.cc
    #6 0x4d60db in testing::Test::Run() /b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/unittest/googletest/src/gtest.cc:2508:5
    #7 0x4d890c in testing::TestInfo::Run() /b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/unittest/googletest/src/gtest.cc:2684:11
    #8 0x4d9cc0 in testing::TestSuite::Run() /b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/unittest/googletest/src/gtest.cc:2816:28
    #9 0x508c51 in testing::internal::UnitTestImpl::RunAllTests() /b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/unittest/googletest/src/gtest.cc:5338:44
    #10 0x50710c in HandleExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool> /b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/unittest/googletest/src/gtest.cc
    #11 0x50710c in testing::UnitTest::Run() /b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/unittest/googletest/src/gtest.cc:4925:10
    #12 0x4b92b0 in RUN_ALL_TESTS /b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/unittest/googletest/include/gtest/gtest.h:2473:46
    #13 0x4b92b0 in main /b/sanitizer-x86_64-linux-fast/build/llvm-project/llvm/utils/unittest/UnitTestMain/TestMain.cpp:50:10
    #14 0x7fc2d313b09a in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2409a)
SUMMARY: AddressSanitizer: 176 byte(s) leaked in 2 allocation(s).
********************
Testing:  0.. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90.. 
********************
Failed Tests (1):
  LLVM-Unit :: Option/./OptionTests/Option.FlagsWithoutValues

Thanks for the revert @kda, I've reapplied with a fix.