fold-const: Fix ICE in extract_muldiv_1 [PR99777]
authorJakub Jelinek <jakub@redhat.com>
Mon, 29 Mar 2021 10:35:32 +0000 (12:35 +0200)
committerJakub Jelinek <jakub@redhat.com>
Mon, 29 Mar 2021 10:35:32 +0000 (12:35 +0200)
commit25e515d2199d555848dfba01fd5364df94096496
treeb827b27f3a4e58de250d8baa24b3fb58179cacae
parentd579e2e76f9469e1b386d693af57c5c4f0ede410
fold-const: Fix ICE in extract_muldiv_1 [PR99777]

extract_muldiv{,_1} is apparently only prepared to handle scalar integer
operations, the callers ensure it by only calling it if the divisor or
one of the multiplicands is INTEGER_CST and because neither multiplication
nor division nor modulo are really supported e.g. for pointer types, nullptr
type etc.  But the CASE_CONVERT handling doesn't really check if it isn't
a cast from some other type kind, so on the testcase we end up trying to
build MULT_EXPR in POINTER_TYPE which ICEs.  A few years ago Marek has
added ANY_INTEGRAL_TYPE_P checks to two spots, but the code uses
TYPE_PRECISION which means something completely different for vector types,
etc.
So IMNSHO we should just punt on conversions from non-integrals or
non-scalar integrals.

2021-03-29  Jakub Jelinek  <jakub@redhat.com>

PR tree-optimization/99777
* fold-const.c (extract_muldiv_1): For conversions, punt on casts from
types other than scalar integral types.

* g++.dg/torture/pr99777.C: New test.
gcc/fold-const.c
gcc/testsuite/g++.dg/torture/pr99777.C [new file with mode: 0644]