diff options
author | Martin Liska <mliska@suse.cz> | 2017-06-28 14:45:59 +0200 |
---|---|---|
committer | Martin Liska <marxin@gcc.gnu.org> | 2017-06-28 12:45:59 +0000 |
commit | 6301008994fa6370261a8c190e4cdf0a27021e63 (patch) | |
tree | 95e68b86727f13f74cf2fc3286161cf1780cce3f /gcc/opts-common.c | |
parent | b1cac008e2629fc225a6ed6a6e748e6caec4dc26 (diff) | |
download | gcc-6301008994fa6370261a8c190e4cdf0a27021e63.zip gcc-6301008994fa6370261a8c190e4cdf0a27021e63.tar.gz gcc-6301008994fa6370261a8c190e4cdf0a27021e63.tar.bz2 |
Introduce IntegerRange for options (PR driver/79659).
2017-06-28 Martin Liska <mliska@suse.cz>
PR driver/79659
* common.opt: Add IntegerRange to various options.
* opt-functions.awk (integer_range_info): New function.
* optc-gen.awk: Add integer_range_info to cl_options struct.
* opts-common.c (decode_cmdline_option): Handle
CL_ERR_INT_RANGE_ARG.
(cmdline_handle_error): Likewise.
* opts.c (print_filtered_help): Show valid interval in
when --help is provided.
* opts.h (struct cl_option): Add range_min and range_max fields.
* config/i386/i386.opt: Add IntegerRange for -mbranch-cost.
2017-06-28 Martin Liska <mliska@suse.cz>
PR driver/79659
* c.opt: Add IntegerRange to various options.
2017-06-28 Martin Liska <mliska@suse.cz>
PR driver/79659
* g++.dg/opt/pr79659.C: New test.
From-SVN: r249734
Diffstat (limited to 'gcc/opts-common.c')
-rw-r--r-- | gcc/opts-common.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/gcc/opts-common.c b/gcc/opts-common.c index f2f7385..0cab42a 100644 --- a/gcc/opts-common.c +++ b/gcc/opts-common.c @@ -661,6 +661,11 @@ decode_cmdline_option (const char **argv, unsigned int lang_mask, value = integral_argument (arg); if (value == -1) errors |= CL_ERR_UINT_ARG; + + /* Reject value out of a range. */ + if (option->range_max != -1 + && (value < option->range_min || value > option->range_max)) + errors |= CL_ERR_INT_RANGE_ARG; } /* If the switch takes an enumerated argument, convert it. */ @@ -1137,6 +1142,13 @@ cmdline_handle_error (location_t loc, const struct cl_option *option, return true; } + if (errors & CL_ERR_INT_RANGE_ARG) + { + error_at (loc, "argument to %qs is not between %d and %d", + option->opt_text, option->range_min, option->range_max); + return true; + } + if (errors & CL_ERR_ENUM_ARG) { const struct cl_enum *e = &cl_enums[option->var_enum]; |