ipa: Check that scalar types that IPA-CP comes up with are sane (PR99122)
authorMartin Jambor <mjambor@suse.cz>
Wed, 24 Mar 2021 19:27:27 +0000 (20:27 +0100)
committerMartin Jambor <mjambor@suse.cz>
Wed, 24 Mar 2021 19:27:27 +0000 (20:27 +0100)
commitf225c6b0c50dc472e0b73b440b572a3bf1514020
tree052304bf379d8d74a2ecb7b3f58b89fec8462e76
parent79cdbabbc4cbf79491c274220928406dff3d4039
ipa: Check that scalar types that IPA-CP comes up with are sane (PR99122)

This patch fixes the last bit of PR 99122 where various bits of IPA
infrastructure are presented with a program with type mismatches that
make it have undefined behavior, and when inlining or performing
IPA-CP, and encountering such mismatch, we basically try to
VIEW_CONVERT_EXPR whatever the caller has into whatever the callee has
or simply use an empty constructor if that cannot be done.  This
however does not work when the callee has VLA parameters because we
ICE in the process.

Richi has already disabled inlining for such cases, this patch avoids
the issue in IPA-CP.  It adds checks that whatever constant the
propagation arrived at is actually compatible or fold_convertible to
the callees formal parameer type.  Unlike in the past, we now have
types of all parameters of functions that we have analyzed, even with
LTO, and so can do it.

This should prevent only bogus propagations.  I have looked at the
effect of the patch on WPA of Firefox and did not have any.

I have bootstrapped and LTO bootstrapped and tested the patch on
x86_64-linux.  OK for trunk?  And perhaps later for GCC 10 too?

Thanks

gcc/ChangeLog:

2021-02-26  Martin Jambor  <mjambor@suse.cz>

PR ipa/99122
* ipa-cp.c (initialize_node_lattices): Mark as bottom all
parameters with unknown type.
(ipacp_value_safe_for_type): New function.
(propagate_vals_across_arith_jfunc): Verify that the constant type
can be used for a type of the formal parameter.
(propagate_vals_across_ancestor): Likewise.
(propagate_scalar_across_jump_function): Likewise.  Pass the type
also to propagate_vals_across_ancestor.

gcc/testsuite/ChangeLog:

2021-02-26  Martin Jambor  <mjambor@suse.cz>

PR ipa/99122
* gcc.dg/pr99122-3.c: Remove -fno-ipa-cp from options.
gcc/ipa-cp.c
gcc/testsuite/gcc.dg/pr99122-3.c