diff options
author | Jakub Jelinek <jakub@redhat.com> | 2022-01-24 11:50:15 +0100 |
---|---|---|
committer | Jakub Jelinek <jakub@redhat.com> | 2022-01-24 11:50:15 +0100 |
commit | 385196adb52d854ebf4f9237e8a521a17c5524c5 (patch) | |
tree | a778a1a0908bb08e591a79a7dd1022a7b42c9fd7 /gcc/doc | |
parent | 2c31a8be4a5db11a0a0e97c366dded6362421086 (diff) | |
download | gcc-385196adb52d854ebf4f9237e8a521a17c5524c5.zip gcc-385196adb52d854ebf4f9237e8a521a17c5524c5.tar.gz gcc-385196adb52d854ebf4f9237e8a521a17c5524c5.tar.bz2 |
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 <jakub@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.
Diffstat (limited to 'gcc/doc')
-rw-r--r-- | gcc/doc/options.texi | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/gcc/doc/options.texi b/gcc/doc/options.texi index d552b64..9387c82 100644 --- a/gcc/doc/options.texi +++ b/gcc/doc/options.texi @@ -132,6 +132,21 @@ be accepted by the driver. This is used for cases such as @option{-march=native} that are processed by the driver so that @samp{gcc -v} shows how the options chosen depended on the system on which the compiler was run. + +@item Set(@var{number}) +This property is optional, required for enumerations used in +@code{EnumSet} options. @var{number} should be decimal number between +1 and 64 inclusive and divides the enumeration into a set of +sets of mutually exclusive arguments. Arguments with the same +@var{number} can't be specified together in the same option, but +arguments with different @var{number} can. @var{value} needs to be +chosen such that a mask of all @var{value} values from the same set +@var{number} bitwise ored doesn't overlap with masks for other sets. +When @code{-foption=arg_from_set1,arg_from_set4} and +@code{-fno-option=arg_from_set3} are used, the effect is that previous +value of the @code{Var} will get bits from set 1 and 4 masks cleared, +ored @code{Value} of @code{arg_from_set1} and @code{arg_from_set4} +and then will get bits from set 3 mask cleared. @end table @item @@ -396,6 +411,16 @@ with the corresponding @samp{Enum} record. The string is checked and converted to the integer specified in the corresponding @samp{EnumValue} record before being passed to option handlers. +@item EnumSet +Must be used together with the @code{Enum(@var{name})} property. +Corresponding @samp{Enum} record must use @code{Set} properties. +The option's argument is either a string from the set like for +@code{Enum(@var{name})}, but with a slightly different behavior that +the whole @code{Var} isn't overwritten, but only the bits in all the +enumeration values with the same set bitwise ored together. +Or option's argument can be a comma separated list of strings where +each string is from a different @code{Set(@var{number})}. + @item Defer The option should be stored in a vector, specified with @code{Var}, for later processing. |