This is an archive of the discontinued LLVM Phabricator instance.

Fix -Wno-error= parsing in clang-format.
ClosedPublic

Authored by fodinabor on Dec 17 2020, 7:07 AM.

Details

Summary

As noted in https://reviews.llvm.org/D86137#2460135 parsing of
the clang-format parameter -Wno-error=unknown fails.
This currently is done by having -Wno-error=unknown as an option.
In this patch this is changed to make -Wno-error= parse an enum into a bit set.
This way the parsing is fixed and also we can possibly add new options easily.

Diff Detail

Event Timeline

fodinabor requested review of this revision.Dec 17 2020, 7:07 AM
fodinabor created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptDec 17 2020, 7:07 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
fodinabor edited projects, added Restricted Project; removed Restricted Project.Dec 17 2020, 7:08 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 17 2020, 7:08 AM

Quoting my questions from the other review, as it should be more appropriate to discuss this here:

The formatting of the --help page is still slightly off (I guess cl::values descriptions are supposed to be single line), so I guess I have to investigate my formatting options here or move the more extensive description somewhere else...

Clang-format options:

  --Werror                   - If set, changes formatting warnings to errors
  --Wno-error=<value>        - If set don't error out on the specified warning type.
    =unknown                 -   If set, unknown format options are only warned about.
This can be used to enable formatting, even if the
configuration contains unknown (newer) options.
Use with caution, as this might lead to dramatically
differing format depending on an option being
supported or not.
  --assume-filename=<string> - Override filename used to determine the language.
                               When reading from stdin, clang-format assumes this
                               filename to determine the language.
  --cursor=<uint>            - The position of the cursor when invoking
...

Btw. is there a way to add tests for command-line options, so this won't happen unnoticed again?

Btw. is there a way to add tests for command-line options, so this won't happen unnoticed again?

I'd guess some lit tests could be used to verify the command line syntax is correct

// RUN: clang-format --Wno-error=unknown --style=`{UnknownKey: true}` --dump-config

If it can't parse that command line, or it maybe parses it incorrectly, clang-format will return non-zero and fail the test

fodinabor updated this revision to Diff 312518.Dec 17 2020, 8:35 AM

Add lit test to ensure behaviour of the -Wno-error=unkown flag.

This revision is now accepted and ready to land.Dec 17 2020, 12:19 PM
fodinabor updated this revision to Diff 312596.Dec 17 2020, 1:00 PM

Update ClangFormat.rst.
This is manually well formatted.. will try to make a new patch in the coming days to actually fix it in the support library.

This revision was landed with ongoing or failed builds.Dec 17 2020, 1:22 PM
This revision was automatically updated to reflect the committed changes.