This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Validate that Init value is within range defined by IntegerRange.


Hello.

I'm sending the patch that does validation of values of Init.
Patch can bootstrap on ppc64le-redhat-linux and survives regression tests.

Ready to be installed?
Martin
>From 46d8c6b9030d677629a4f7c647efe73f4c2ddf0c Mon Sep 17 00:00:00 2001
From: marxin <mliska@suse.cz>
Date: Mon, 10 Jul 2017 10:33:49 +0200
Subject: [PATCH] Validate that Init value is within range defined by
 IntegerRange.

gcc/ChangeLog:

2017-07-13  Martin Liska  <mliska@suse.cz>

	* opt-functions.awk: Add validation of value of Init.
	* optc-gen.awk: Pass new argument.
---
 gcc/opt-functions.awk | 4 +++-
 gcc/optc-gen.awk      | 3 ++-
 2 files changed, 5 insertions(+), 2 deletions(-)

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]