On 07/07/2017 09:20 PM, Martin Sebor wrote:
> A conflict in my patch for bug 81345 made me notice that r249734
> recently added a new option property, IntegerRange.  The change
> below adds brief documentation of the property to the manual.
> 
> Martin, can you please check to make sure I didn't miss anything?
> 
> Btw., while experimenting with the property I noticed that there
> is no error when option that specifies IntegerRange is set in
> the .opt file to a value outside that range.  Would it be hard
> to add some checks the the awk scripts to validate that the
> argument values are in the range?  It might help avoid bugs
> similar to 81345).

Sure, please take a look at attached patch. Can you please test it?

> 
> By the way of an example, the following invalid specification
> is accepted but then causes errors when GCC runs.
> 
> Wfoobar
> C ObjC C++ ObjC++ Warning Alias(Wfoobar=, 1, 0)
> 
> Wfoobar=
> C ObjC C++ ObjC++ Joined RejectNegative UInteger Var(warn_foobar) Warning 
> LangEnabledBy(C ObjC C++ ObjC++, Wall, 2, 0) Init (7) IntegerRange(3, 5)

Here one needs to have 'Init (7)' without space!

> 
> Martin
> 
> diff --git a/gcc/doc/options.texi b/gcc/doc/options.texi
> index 3b68aab..af56e9f 100644
> --- a/gcc/doc/options.texi
> +++ b/gcc/doc/options.texi
> @@ -264,6 +264,12 @@ option handler.  @code{UInteger} should also be used on 
> options like
>  @code{-falign-loops}=@var{n} are supported to make sure the saved
>  options are given a full integer.
> 
> +@item IntegerRange(@var{min}, @var{max})
> +The option's integer argument is expected to be in the range specified
> +by @var{min} and @var{max}, inclusive.  The option parser will check
> +and reject option arguments that are outside the range before passing
> +it to the relevant option handler.

LGTM, thanks for the documentation entry.

Martin

> +
>  @item ToLower
>  The option's argument should be converted to lowercase as part of
>  putting it in canonical form, and before comparing with the strings

>From 443280fdc8a1215c8045752033f8290dd4e493c9 Mon Sep 17 00:00:00 2001
From: marxin <mli...@suse.cz>
Date: Mon, 10 Jul 2017 10:33:49 +0200
Subject: [PATCH] To test version.

---
 gcc/common.opt        | 7 +++++++
 gcc/opt-functions.awk | 4 +++-
 gcc/optc-gen.awk      | 3 ++-
 3 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/gcc/common.opt b/gcc/common.opt
index e81165c488b..2dd2f79f6ab 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -3109,4 +3109,11 @@ fipa-ra
 Common Report Var(flag_ipa_ra) Optimization
 Use caller save register across calls if possible.
 
+
+Wfoobar
+C ObjC C++ ObjC++ Warning Alias(Wfoobar=, 1, 0)
+
+Wfoobar=
+C ObjC C++ ObjC++ Joined RejectNegative UInteger Var(warn_foobar) Warning LangEnabledBy(C ObjC C++ ObjC++, Wall, 2, 0) Init(7) IntegerRange(3, 5)
+
 ; This comment is to ensure we retain the blank line above.
diff --git a/gcc/opt-functions.awk b/gcc/opt-functions.awk
index ad0b52c0903..5ee93f12feb 100644
--- a/gcc/opt-functions.awk
+++ b/gcc/opt-functions.awk
@@ -314,11 +314,13 @@ function search_var_name(name, opt_numbers, opts, flags, n_opts)
     return ""
 }
 
-function integer_range_info(range_option)
+function integer_range_info(range_option, init, option)
 {
     if (range_option != "") {
 	start = nth_arg(0, range_option);
 	end = nth_arg(1, range_option);
+	if (init != "" && init != "-1" && (init < start || init > end))
+	  print "#error initial value " init " of '" option "' must be in range [" start "," end "]"
 	return start ", " end
     }
     else
diff --git a/gcc/optc-gen.awk b/gcc/optc-gen.awk
index 45b1b95e7ec..3cb0005ba40 100644
--- a/gcc/optc-gen.awk
+++ b/gcc/optc-gen.awk
@@ -400,7 +400,8 @@ for (i = 0; i < n_opts; i++) {
 		       "    0, %s,\n",
 		       cl_flags, cl_bit_fields)
 	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)
+	       var_set(flags[i]), integer_range_info(opt_args("IntegerRange", flags[i]),
+		    opt_args("Init", flags[i]), opts[i]), comma)
 }
 
 print "};"
-- 
2.13.2

Reply via email to