https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99122
--- Comment #17 from Richard Biener <rguenth at gcc dot gnu.org> ---
(In reply to Martin Jambor from comment #16)
> For the IPA-CP ICE, I am still running some tests, but I am currently
> leaning towards the following. It might in theory disable IPA-CP in some
> strange K&R corner cases (I am searching for those with the tests), but I
> cannot say I care too much even if it does:
>
> diff --git a/gcc/ipa-cp.c b/gcc/ipa-cp.c
> index 167913cb927..4c8b76c09be 100644
> --- a/gcc/ipa-cp.c
> +++ b/gcc/ipa-cp.c
> @@ -1186,6 +1186,20 @@ set_single_call_flag (cgraph_node *node, void *)
> return false;
> }
>
> +/* Return true if the Ith formal parameter in function described by INFO
> has a
> + type that is known and safe to accept constants. */
> +
> +static bool
> +ipa_cp_param_has_safe_type_p (ipa_node_params *info, int i)
> +{
> + tree t = ipa_get_type (info, i);
> + if (!t)
> + return false;
> + /* Attempting to propagate to parameters that are VLAs runs afoul
> limitations
> + of how clone materialization implementation. */
> + return TREE_CODE (TYPE_SIZE (t)) == INTEGER_CST;
there's variably_modified_type_p (you can pass NULL_TREE for the fndecl)
which is more to the point. Otherwise it looks reasonable. Does IPA CP
do things like IPA SRA and split aggregates? I wonder in which cases
IPA CP would derive "constants" for aggregates, so why are aggregate
parameters even tracked?
> +}
> +
> /* Initialize ipcp_lattices. */
>
> static void
> @@ -1277,7 +1291,8 @@ initialize_node_lattices (struct cgraph_node *node)
> ipcp_param_lattices *plats = ipa_get_parm_lattices (info, i);
> if (disable
> || (pre_modified && (surviving_params.length () <= (unsigned) i
> - || !surviving_params[i])))
> + || !surviving_params[i]))
> + || !ipa_cp_param_has_safe_type_p (info, i))
> {
> plats->itself.set_to_bottom ();
> plats->ctxlat.set_to_bottom ();