Commit 63010089 by Martin Liska Committed by Martin Liska

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
parent b1cac008
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 Marc Glisse <marc.glisse@inria.fr>
* match.pd ((X & ~Y) | (~X & Y)): Generalize to + and ^.
......
2017-06-28 Martin Liska <mliska@suse.cz>
PR driver/79659
* c.opt: Add IntegerRange to various options.
2017-06-26 Marek Polacek <polacek@redhat.com>
PR c/80116
......
......@@ -541,7 +541,7 @@ C ObjC C++ ObjC++ Var(warn_format_nonliteral) Warning LangEnabledBy(C ObjC C++ O
Warn about format strings that are not literals.
Wformat-overflow
C ObjC C++ LTO ObjC++ Warning Alias(Wformat-overflow=, 1, 0)
C ObjC C++ LTO ObjC++ Warning Alias(Wformat-overflow=, 1, 0) IntegerRange(0, 2)
Warn about function calls with format strings that write past the end
of the destination region. Same as -Wformat-overflow=1.
......@@ -567,16 +567,16 @@ C ObjC C++ ObjC++ Var(warn_format_zero_length) Warning LangEnabledBy(C ObjC C++
Warn about zero-length formats.
Wformat=
C ObjC C++ ObjC++ Joined RejectNegative UInteger Var(warn_format) Warning LangEnabledBy(C ObjC C++ ObjC++,Wall, 1, 0)
C ObjC C++ ObjC++ Joined RejectNegative UInteger Var(warn_format) Warning LangEnabledBy(C ObjC C++ ObjC++,Wall, 1, 0) IntegerRange(0, 2)
Warn about printf/scanf/strftime/strfmon format string anomalies.
Wformat-overflow=
C ObjC C++ LTO ObjC++ Joined RejectNegative UInteger Var(warn_format_overflow) Warning LangEnabledBy(C ObjC C++ ObjC++,Wformat=, warn_format >= 1, 0)
C ObjC C++ LTO ObjC++ Joined RejectNegative UInteger Var(warn_format_overflow) Warning LangEnabledBy(C ObjC C++ ObjC++,Wformat=, warn_format >= 1, 0) IntegerRange(0, 2)
Warn about function calls with format strings that write past the end
of the destination region.
Wformat-truncation=
C ObjC C++ ObjC++ Joined RejectNegative UInteger Var(warn_format_trunc) Warning LangEnabledBy(C ObjC C++ ObjC++,Wformat=, warn_format >= 1, 0)
C ObjC C++ ObjC++ Joined RejectNegative UInteger Var(warn_format_trunc) Warning LangEnabledBy(C ObjC C++ ObjC++,Wformat=, warn_format >= 1, 0) IntegerRange(0, 2)
Warn about calls to snprintf and similar functions that truncate output.
Wignored-qualifiers
......@@ -732,7 +732,7 @@ Warn about buffer overflow in string manipulation functions like memcpy
and strcpy.
Wstringop-overflow=
C ObjC C++ ObjC++ Joined RejectNegative UInteger Var(warn_stringop_overflow) Init(2) Warning LangEnabledBy(C ObjC C++ ObjC++, Wall)
C ObjC C++ ObjC++ Joined RejectNegative UInteger Var(warn_stringop_overflow) Init(2) Warning LangEnabledBy(C ObjC C++ ObjC++, Wall) IntegerRange(0, 4)
Under the control of Object Size type, warn about buffer overflow in string
manipulation functions like memcpy and strcpy.
......@@ -936,7 +936,7 @@ C++ Warning Alias(Wplacement-new=, 1, 0)
Warn for placement new expressions with undefined behavior.
Wplacement-new=
C++ Joined RejectNegative UInteger Var(warn_placement_new) Init(-1) Warning
C++ Joined RejectNegative UInteger Var(warn_placement_new) Init(-1) Warning IntegerRange(0, 2)
Warn for placement new expressions with undefined behavior.
Wredundant-decls
......@@ -976,7 +976,7 @@ C ObjC C++ ObjC++ Warning Alias(Wshift-overflow=, 1, 0)
Warn if left shift of a signed value overflows.
Wshift-overflow=
C ObjC C++ ObjC++ Joined RejectNegative UInteger Var(warn_shift_overflow) Init(-1) Warning
C ObjC C++ ObjC++ Joined RejectNegative UInteger Var(warn_shift_overflow) Init(-1) Warning IntegerRange(0, 2)
Warn if left shift of a signed value overflows.
Wshift-count-negative
......@@ -1016,11 +1016,11 @@ C ObjC Var(warn_strict_prototypes) Warning
Warn about unprototyped function declarations.
Wstrict-aliasing=
C ObjC C++ ObjC++ LangEnabledBy(C ObjC C++ ObjC++,Wall, 3, 0)
C ObjC C++ ObjC++ LangEnabledBy(C ObjC C++ ObjC++,Wall, 3, 0) IntegerRange(0, 3)
;
Wstrict-overflow=
C ObjC C++ ObjC++ LangEnabledBy(C ObjC C++ ObjC++,Wall, 1, 0)
C ObjC C++ ObjC++ LangEnabledBy(C ObjC C++ ObjC++,Wall, 1, 0) IntegerRange(0, 5)
;
Wstrict-selector-match
......@@ -1108,7 +1108,7 @@ C ObjC C++ ObjC++ Warning Alias(Wunused-const-variable=, 2, 0)
Warn when a const variable is unused.
Wunused-const-variable=
C ObjC C++ ObjC++ Joined RejectNegative UInteger Var(warn_unused_const_variable) Warning LangEnabledBy(C ObjC,Wunused-variable, 1, 0)
C ObjC C++ ObjC++ Joined RejectNegative UInteger Var(warn_unused_const_variable) Warning LangEnabledBy(C ObjC,Wunused-variable, 1, 0) IntegerRange(0, 2)
Warn when a const variable is unused.
Wvariadic-macros
......
......@@ -546,7 +546,7 @@ Common Var(warn_array_bounds) Warning
Warn if an array is accessed out of bounds.
Warray-bounds=
Common Joined RejectNegative UInteger Var(warn_array_bounds) Warning
Common Joined RejectNegative UInteger Var(warn_array_bounds) Warning IntegerRange(0, 2)
Warn if an array is accessed out of bounds.
Wattributes
......@@ -601,7 +601,7 @@ Wimplicit-fallthrough
Common Alias(Wimplicit-fallthrough=,3,0) Warning
Wimplicit-fallthrough=
Common Var(warn_implicit_fallthrough) RejectNegative Joined UInteger Warning
Common Var(warn_implicit_fallthrough) RejectNegative Joined UInteger Warning IntegerRange(0, 5)
Warn when a switch case falls through.
Winline
......@@ -1778,7 +1778,7 @@ Specify the algorithm to partition symbols and vars at linktime.
; The initial value of -1 comes from Z_DEFAULT_COMPRESSION in zlib.h.
flto-compression-level=
Common Joined RejectNegative UInteger Var(flag_lto_compression_level) Init(-1)
Common Joined RejectNegative UInteger Var(flag_lto_compression_level) Init(-1) IntegerRange(0, 9)
-flto-compression-level=<number> Use zlib compression level <number> for IL.
flto-odr-type-merging
......@@ -2061,7 +2061,7 @@ Tell DSE that the storage for a C++ object is dead when the constructor
starts and when the destructor finishes.
flifetime-dse=
Common Joined RejectNegative UInteger Var(flag_lifetime_dse) Optimization
Common Joined RejectNegative UInteger Var(flag_lifetime_dse) Optimization IntegerRange(0, 2)
flive-range-shrinkage
Common Report Var(flag_live_range_shrinkage) Init(0) Optimization
......
......@@ -267,8 +267,8 @@ EnumValue
Enum(asm_dialect) String(att) Value(ASM_ATT)
mbranch-cost=
Target RejectNegative Joined UInteger Var(ix86_branch_cost)
Branches are this expensive (1-5, arbitrary units).
Target RejectNegative Joined UInteger Var(ix86_branch_cost) IntegerRange(1, 5)
Branches are this expensive (arbitrary units).
mlarge-data-threshold=
Target RejectNegative Joined UInteger Var(ix86_section_threshold) Init(DEFAULT_LARGE_SECTION_THRESHOLD)
......
......@@ -314,6 +314,17 @@ function search_var_name(name, opt_numbers, opts, flags, n_opts)
return ""
}
function integer_range_info(range_option)
{
if (range_option != "") {
start = nth_arg(0, range_option);
end = nth_arg(1, range_option);
return start ", " end
}
else
return "-1, -1"
}
# Handle LangEnabledBy(ENABLED_BY_LANGS, ENABLEDBY_NAME, ENABLEDBY_POSARG,
# ENABLEDBY_NEGARG). This function does not return anything.
function lang_enabled_by(enabledby_langs, enabledby_name, enabledby_posarg, enabledby_negarg)
......
......@@ -399,8 +399,8 @@ for (i = 0; i < n_opts; i++) {
printf(" %s,\n" \
" 0, %s,\n",
cl_flags, cl_bit_fields)
printf(" %s, %s }%s\n", var_ref(opts[i], flags[i]),
var_set(flags[i]), comma)
printf(" %s, %s, %s }%s\n", var_ref(opts[i], flags[i]),
var_set(flags[i]), integer_range_info(opt_args("IntegerRange", flags[i])), comma)
}
print "};"
......
......@@ -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];
......
......@@ -1253,6 +1253,15 @@ print_filtered_help (unsigned int include_flags,
help = new_help;
}
if (option->range_max != -1)
{
char b[128];
snprintf (b, sizeof (b), "<%d,%d>", option->range_min,
option->range_max);
opt = concat (opt, b, NULL);
len += strlen (b);
}
wrap_help (help, opt, len, columns);
displayed = true;
......
......@@ -110,6 +110,10 @@ struct cl_option
enum cl_var_type var_type;
/* Value or bit-mask with which to set a field. */
HOST_WIDE_INT var_value;
/* Range info minimum, or -1. */
int range_min;
/* Range info maximum, or -1. */
int range_max;
};
/* Records that the state of an option consists of SIZE bytes starting
......@@ -200,8 +204,9 @@ extern const unsigned int cl_enums_count;
#define CL_ERR_MISSING_ARG (1 << 1) /* Argument required but missing. */
#define CL_ERR_WRONG_LANG (1 << 2) /* Option for wrong language. */
#define CL_ERR_UINT_ARG (1 << 3) /* Bad unsigned integer argument. */
#define CL_ERR_ENUM_ARG (1 << 4) /* Bad enumerated argument. */
#define CL_ERR_NEGATIVE (1 << 5) /* Negative form of option
#define CL_ERR_INT_RANGE_ARG (1 << 4) /* Bad unsigned integer argument. */
#define CL_ERR_ENUM_ARG (1 << 5) /* Bad enumerated argument. */
#define CL_ERR_NEGATIVE (1 << 6) /* Negative form of option
not permitted (together
with OPT_SPECIAL_unknown). */
......
2017-06-28 Martin Liska <mliska@suse.cz>
PR driver/79659
* g++.dg/opt/pr79659.C: New test.
2017-06-28 Christophe Lyon <christophe.lyon@linaro.org>
* gcc.dg/tree-ssa/copy-sign-1.c: Add c99_runtime effective target
......
// PR target/79659
// { dg-do compile }
// { dg-options "-flifetime-dse=123456" }
// { dg-error "is not between 0 and 2" "" { target *-*-* } 0 }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment