https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104158

--- Comment #8 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <ja...@gcc.gnu.org>:

https://gcc.gnu.org/g:385196adb52d854ebf4f9237e8a521a17c5524c5

commit r12-6839-g385196adb52d854ebf4f9237e8a521a17c5524c5
Author: Jakub Jelinek <ja...@redhat.com>
Date:   Mon Jan 24 11:50:15 2022 +0100

    options: Add EnumSet and Set property support [PR104158]

    The following patch is infrastructure support for at least 3 different
    options that need changes:
    1) PR104158 talks about a regression with the -fsanitizer-coverage=
       option; in GCC 11 and older and on trunk prior to r12-1177, this
       option behaved similarly to -f{,no-}sanitizer{,-recover}= options,
       namely that the option allows negative and argument of the option
       is a list of strings, each of them has some enumerator and
       -fsanitize-coverage= enabled those bits in the underlying
       flag_sanitize_coverage, while -fno-sanitize-coverage= disabled them.
       So, -fsanitize-coverage=trace-pc,trace-cmp was equivalent to
       -fsanitize-coverage=trace-pc -fsanitize-coverage=trace-cmp and both
       set flag_sanitize_coverage to
       (SANITIZE_COV_TRACE_PC | SANITIZE_COV_TRACE_CMP)
       Also, e.g.
       -fsanitize-coverage=trace-pc,trace-cmp -fno-sanitize-coverage=trace-pc
       would in the end set flag_sanitize_coverage to
       SANITIZE_COV_TRACE_CMP (first set both bits, then subtract one)
       The r12-1177 change, I think done to improve argument misspelling
       diagnostic, changed the option incompatibly in multiple ways,
       -fno-sanitize-coverage= is now rejected, only a single argument
       is allowed, not multiple and
       -fsanitize-coverage=trace-pc -fsanitize-coverage=trace-cmp
       enables just SANITIZE_COV_TRACE_CMP and not both (each option
       overrides the previous value)
    2) Thomas Koenig wants to extend Fortran -fconvert= option for the
       ppc64le real(kind=16) swapping support; currently the option
       accepts -fconvert={native,swap,big-endian,little-endian} and the
       intent is to add support for -fconvert=r16_ibm and -fconvert=r16_ieee
       (that alone is just normal Enum), but also to handle
       -fconvert=swap,r16_ieee or -fconvert=r16_ieee,big-endian but not
       -fconvert=big-endian,little-endian - the
       native/swap/big-endian/little-endian are one mutually exclusive set
       and r16_ieee/r16_ibm another one.
       See https://gcc.gnu.org/pipermail/gcc-patches/2022-January/587943.html
       and thread around that.
    3) Similarly Marek Polacek wants to extend the -Wbidi-chars= option,
       such that it will handle not just the current
       -Wbidi-chars={none,bidirectional,any}, but also -Wbidi-chars=ucn
       and bidirectional,ucn and ucn,any etc.  Again two separate sets,
       one none/bidirectional/any and another one ucn.
       See https://gcc.gnu.org/pipermail/gcc-patches/2022-January/588960.html

    The following patch adds framework for this and I'll post incremental
    patches for 1) and 2).
    As I've tried to document, such options are marked by additional
    EnumSet property on the option and in that case all the EnumValues
    in the Enum referenced from it must use a new Set property with set
    number (initially I wanted just mark last enumerator in each mutually
    exclusive set, but optionlist is sorted and so it doesn't really work
    well).  So e.g. for the Fortran -fconvert=, one specifies:
    fconvert=
    Fortran RejectNegative Joined Enum(gfc_convert) EnumSet Var(flag_convert)
Init(GFC_FLAG_CONVERT_NATIVE)
    -fconvert=<big-endian|little-endian|native|swap|r16_ieee|r16_ibm>      The
endianness used for unformatted files.

    Enum
    Name(gfc_convert) Type(enum gfc_convert) UnknownError(Unrecognized option
to endianness value: %qs)

    EnumValue
    Enum(gfc_convert) String(big-endian) Value(GFC_FLAG_CONVERT_BIG) Set(1)

    EnumValue
    Enum(gfc_convert) String(little-endian) Value(GFC_FLAG_CONVERT_LITTLE)
Set(1)

    EnumValue
    Enum(gfc_convert) String(native) Value(GFC_FLAG_CONVERT_NATIVE) Set(1)

    EnumValue
    Enum(gfc_convert) String(swap) Value(GFC_FLAG_CONVERT_SWAP) Set(1)

    EnumValue
    Enum(gfc_convert) String(r16_ieee) Value(GFC_FLAG_CONVERT_R16_IEEE) Set(2)

    EnumValue
    Enum(gfc_convert) String(r16_ibm) Value(GFC_FLAG_CONVERT_R16_IBM) Set(2)

    and this says to the option handling code that
    1) if only one arg is specified to one instance of the option, it can be
any
    of those 6
    2) if two args are specified, one has to be from the first 4 and another
    from the last 2, in any order
    3) at most 2 args may be specified (there are just 2 sets)

    There is a requirement on the Value values checked in self-test, the
    values from one set ored together must be disjunct from values from
    another set ored together.  In the Fortran case, the first 4 are 0-3
    so mask is 3, and the last 2 are 4 and 8, so mask is 12.
    When say -fconvert=big-endian is specified, it sets the first set
    to GFC_FLAG_CONVERT_BIG (2) but doesn't modify whatever value the
    other set had, so e.g.
    -fconvert=big-endian -fconvert=r16_ieee
    -fconvert=r16_ieee -fconvert=big-endian
    -fconvert=r16_ieee,big_endian
    -fconvert=big_endian,r16_ieee
    all behave the same.

    Also, with the EnumSet support, it is now possible to allow
    not specifying RejectNegative - we can set some set's value and
    then clear it and set it again to some other value etc.

    I think with the 2) patch I achieve what we want for Fortran, for 1)
    the only behavior from gcc 11 is that
    -fsanitize-coverage=trace-cmp,trace-cmp is now rejected.
    This is mainly from the desire to disallow
    -fconvert=big-endian,little-endian or -Wbidi-chars=bidirectional,any
    etc. where it would be confusing to users what exactly it means.
    But it is the only from these options that actually acts as an Enum
    bit set, each enumerator can be specified with all the others.
    So one option would be stop requiring the EnumSet implies Set properties
    must be specified and just require that either they are specified on all
    EnumValues, or on none of them; the latter case would be for
    -fsanitize-coverage= and the non-Set case would mean that all the
    EnumValues need to have disjoint Value bitmasks and that they can
    be all specified and unlike the Set case also repeated.
    Thoughts on this?

    2022-01-24  Jakub Jelinek  <ja...@redhat.com>

            PR sanitizer/104158
            * opt-functions.awk (var_set): Handle EnumSet property.
            * optc-gen.awk: Don't disallow RejectNegative if EnumSet is
            specified.
            * opt-read.awk: Handle Set property.
            * opts.h (CL_ENUM_SET_SHIFT, CL_ERR_ENUM_SET_ARG): Define.
            (struct cl_decoded_option): Mention enum in value description.
            Add mask member.
            (set_option): Add mask argument defaulted to 0.
            * opts.cc (test_enum_sets): New function.
            (opts_cc_tests): Call it.
            * opts-common.cc (enum_arg_to_value): Change return argument
            from bool to int, on success return index into the cl_enum_arg
            array, on failure -1.  Add len argument, if non-0, use strncmp
            instead of strcmp.
            (opt_enum_arg_to_value): Adjust caller.
            (decode_cmdline_option): Handle EnumSet represented as
            CLVC_ENUM with non-zero var_value.  Initialize decoded->mask.
            (decode_cmdline_options_to_array): CLear opt_array[0].mask.
            (handle_option): Pass decoded->mask to set_options last argument.
            (generate_option): Clear decoded->mask.
            (generate_option_input_file): Likewise.
            (cmdline_handle_error): Handle CL_ERR_ENUM_SET_ARG.
            (set_option): Add mask argument, use it for CLVC_ENUM.
            (control_warning_option): Adjust enum_arg_to_value caller.
            * doc/options.texi: Document Set and EnumSet properties.

Reply via email to