ipa: Avoid invalid gimple when IPA-CP and IPA-SRA disagree on types (108384)
authorMartin Jambor <mjambor@suse.cz>
Fri, 3 Feb 2023 12:28:24 +0000 (13:28 +0100)
committerMartin Jambor <mjambor@suse.cz>
Fri, 3 Feb 2023 12:29:59 +0000 (13:29 +0100)
commite8109bd87766be88e83fe88a44433dae16358a02
tree7a257f734540699ac9341c55edd26e63475cfa95
parent0b1ce70a813b98ef2893779d14ad6c90c5d06a71
ipa: Avoid invalid gimple when IPA-CP and IPA-SRA disagree on types (108384)

When the compiled program contains type mismatches between callers and
callees when it comes to a parameter, IPA-CP can try to propagate one
constant from callers while IPA-SRA may try to split a parameter
expecting a value of a different size on the same offset.  This then
currently leads to creation of a VIEW_CONVERT_EXPR with mismatching
type sizes of LHS and RHS which is correctly flagged by the GIMPLE
verifier as invalid.

It seems that the best course of action is to try and avoid the
situation altogether and so this patch adds a check to IPA-SRA that
peeks into the result of IPA-CP and when it sees a value on the same
offset but with a mismatching size, it just decides to leave that
particular parameter be.

gcc/ChangeLog:

2023-02-02  Martin Jambor  <mjambor@suse.cz>

PR ipa/108384
* ipa-sra.cc (push_param_adjustments_for_index): Remove a size check
when comparing to an IPA-CP value.
(dump_list_of_param_indices): New function.
(adjust_parameter_descriptions): Check for mismatching IPA-CP values.
Dump removed candidates using dump_list_of_param_indices.
* ipa-param-manipulation.cc
(ipa_param_body_adjustments::modify_expression): Add assert checking
sizes of a VIEW_CONVERT_EXPR will match.
(ipa_param_body_adjustments::modify_assignment): Likewise.

gcc/testsuite/ChangeLog:

2023-02-02  Martin Jambor  <mjambor@suse.cz>

PR ipa/108384
* gcc.dg/ipa/pr108384.c: New test.
gcc/ipa-param-manipulation.cc
gcc/ipa-sra.cc
gcc/testsuite/gcc.dg/ipa/pr108384.c [new file with mode: 0644]