[Patch] Fix ICE on string comparison

Richard Guenther richard.guenther@gmail.com
Sun Dec 7 22:16:00 GMT 2008


On Sun, Dec 7, 2008 at 11:04 PM, Eric Botcazou <ebotcazou@adacore.com> wrote:
> Hi,
>
> this is a regression present on the mainline:
>
> +===========================GNAT BUG DETECTED==============================+
> | 4.4.0 20081206 (experimental) [trunk revision 142519] (i586-suse-linux-gnu)
> GCC error:|
> | in recalculate_side_effects, at gimple.c:3113
>
> recalculate_side_effects is called from gimplify_expr on an INTEGER_CST and it
> doesn't like that.  In the .original dump:
>
> exerc_2__bool_io__put__2 ("True" == "TRUE", (const
> ada__text_io__field___XDLU_0__255) bool_io__default_width, (integer)
> bool_io__default_setting);
>
> The string comparison is folded to 0 by gimplify_scalar_mode_aggregate_compare
> so at the end of the block
>
>            case tcc_comparison:
>              /* Handle comparison of objects of non scalar mode aggregates
>                 with a call to memcmp.  It would be nice to only have to do
>                 this for variable-sized objects, but then we'd have to allow
>                 the same nest of reference nodes we allow for MODIFY_EXPR and
>                 that's too complex.
>
>                 Compare scalar mode aggregates as scalar mode values.  Using
>                 memcmp for them would be very inefficient at best, and is
>                 plain wrong if bitfields are involved.  */
>                {
>                  tree type = TREE_TYPE (TREE_OPERAND (*expr_p, 1));
>
>                  if (!AGGREGATE_TYPE_P (type))
>                    goto expr_2;
>                  else if (TYPE_MODE (type) != BLKmode)
>                    ret = gimplify_scalar_mode_aggregate_compare (expr_p);
>                  else
>                    ret = gimplify_variable_sized_compare (expr_p);
>
>                  break;
>                }
>
> *expr_p is 0, causing
>
>  recalculate_side_effects (*expr_p);
>
> to abort.
>
> This didn't happen on the 4.3 branch because the comparison was not folded
> to 0 (the VIEW_CONVERT<STRING_CST>s were not turned into INTEGER_CSTs).
>
> Hence the proposed fix, tested on i586-suse-linux, OK for mainline?

I think it is better to handle tcc_constant properly in recalculate_side_effects
(by doing nothing).

Ok with that change.

Thanks,
Richard.

>
> 2008-12-07  Eric Botcazou  <ebotcazou@adacore.com>
>
>        * expr.c (gimplify_expr) <tcc_comparison>: Do not recalculate
>        side-effects if the comparison has been entirely folded.
>
>
> 2008-12-07  Eric Botcazou  <ebotcazou@adacore.com>
>
>        * gnat.dg/string_comparison.adb: New test.
>
>
> --
> Eric Botcazou
>



More information about the Gcc-patches mailing list