[V4,02/11] opt-functions.awk: fix comparison of limit, begin and end

Message ID 20190827234718.5844-3-jose.marchesi@oracle.com
State New
Headers show
Series
  • eBPF support for GCC
Related show

Commit Message

Jose E. Marchesi Aug. 27, 2019, 11:47 p.m.
The function integer_range_info makes sure that, if provided, the
initial value fills in the especified range.  However, it is necessary
to convert the values to a numerical context before comparing, to make
sure awk is using arithmetical order and not lexicographical order.

gcc/ChangeLog:

	* opt-functions.awk (integer_range_info): Make sure values are in
	numeric context before operating with them.
---
 gcc/ChangeLog         | 5 +++++
 gcc/opt-functions.awk | 5 +++--
 2 files changed, 8 insertions(+), 2 deletions(-)

-- 
2.11.0

Comments

Ulrich Drepper Aug. 28, 2019, 4:37 a.m. | #1
On Wed, Aug 28, 2019 at 1:47 AM Jose E. Marchesi <jose.marchesi@oracle.com>
wrote:

>  function integer_range_info(range_option, init, option)

>  {

>      if (range_option != "") {

> -       start = nth_arg(0, range_option);

> -       end = nth_arg(1, range_option);

> +       init = init + 0;

> +       start = nth_arg(0, range_option) + 0;

> +       end = nth_arg(1, range_option) + 0;

>         if (init != "" && init != "-1" && (init < start || init > end))



In this case the test for init != "" is at least unnecessary.

Maybe something else has to be used.  I didn't trace the uses but if init
is deliberately set to "" then the test would have to be replaced with init
!= 0.
Jose E. Marchesi Aug. 28, 2019, 11:49 a.m. | #2
>  function integer_range_info(range_option, init, option)

    >  {

    >      if (range_option != "") {

    > -       start = nth_arg(0, range_option);

    > -       end = nth_arg(1, range_option);

    > +       init = init + 0;

    > +       start = nth_arg(0, range_option) + 0;

    > +       end = nth_arg(1, range_option) + 0;

    >         if (init != "" && init != "-1" && (init < start || init > end))

    
    
    In this case the test for init != "" is at least unnecessary.

Right! Thanks for noticing.

    Maybe something else has to be used.  I didn't trace the uses but if init
    is deliberately set to "" then the test would have to be replaced with init
    != 0.

Hm, in principle Init() can specify any non-negative number, including
0... what about a conservative approach that fixes the ordering problem
but leaves the "special cases" -1 and "" with exactly the same semantics
than before:

function integer_range_info(range_option, init, option)
{
    if (range_option != "") {
	ival = init + 0;
	start = nth_arg(0, range_option) + 0;
	end = nth_arg(1, range_option) + 0;
	if (init != "" && init != "-1" && (ival < start || ival > end))
	  print "#error initial value " init " of '" option "' must be in range [" start "," end "]"
	return start ", " end
    }
    else
        return "-1, -1"
}

Patch

diff --git a/gcc/opt-functions.awk b/gcc/opt-functions.awk
index 1190e6d6b66..0b28a6c3bff 100644
--- a/gcc/opt-functions.awk
+++ b/gcc/opt-functions.awk
@@ -346,8 +346,9 @@  function search_var_name(name, opt_numbers, opts, flags, n_opts)
 function integer_range_info(range_option, init, option)
 {
     if (range_option != "") {
-	start = nth_arg(0, range_option);
-	end = nth_arg(1, range_option);
+	init = init + 0;
+	start = nth_arg(0, range_option) + 0;
+	end = nth_arg(1, range_option) + 0;
 	if (init != "" && init != "-1" && (init < start || init > end))
 	  print "#error initial value " init " of '" option "' must be in range [" start "," end "]"
 	return start ", " end