[m-rev.] diff: Avoid gcc warning about tautological comparison in test case.

Zoltan Somogyi zoltan.somogyi at runbox.com
Fri Oct 19 17:33:48 AEDT 2018



On Fri, 19 Oct 2018 16:54:03 +1100, Peter Wang <novalazy at gmail.com> wrote:
>  int_gen_toto(X, Y) :-
> -    ( compare(=, X, X) ->
> +    ( compare(=, X, X + 0) ->
>          gen_toto_float(Y)
>      ;
>          error("oops")
>      ).

I get the code that the compiler complains about only when
I compile this test case with a compiler that contains the diff
I committed a week ago to effectively inline builtin_compare_int.
It seems that as long as we called builtin_compare_int,
the C compiler did not know that a value was being compared
with itself; now that it sees the raw comparisons that builtin_compare_int
uses, it does know.

The fix seems obvious: make simplify_improve_builtin_compare
look for situations where a value is compared with itself,
and replace compare(Result, X, X) with Result = (=).

Peter, do you want to do it, or should I? I should warn you:
my C compiler is so old that it does not generate a warning
for self-comparisons, so there may be further problems
hiding behind the above fix (which may therefore be
only partial.)

Zoltan.


More information about the reviews mailing list