]> git.ipfire.org Git - thirdparty/gcc.git/commit
expr: Fix REDUCE_BIT_FIELD in multiplication expansion [PR114054]
authorJakub Jelinek <jakub@redhat.com>
Fri, 23 Feb 2024 10:38:18 +0000 (11:38 +0100)
committerJakub Jelinek <jakub@redhat.com>
Fri, 23 Feb 2024 10:38:18 +0000 (11:38 +0100)
commit22121546e0315d25ee419d2389022e3974750885
treefa9f1290961e5e389dc68f34e4b26c057baf6ad3
parentbe1f2bc4522f772184a4d16d8f3fec75baed89cf
expr: Fix REDUCE_BIT_FIELD in multiplication expansion [PR114054]

The following testcase ICEs, because the REDUCE_BIT_FIELD macro uses
the target variable implicitly:
 #define REDUCE_BIT_FIELD(expr)  (reduce_bit_field                         \
                                  ? reduce_to_bit_field_precision ((expr), \
                                                                   target, \
                                                                   type)   \
                                  : (expr))
and so when the code below reuses the target variable, documented to be
   The value may be stored in TARGET if TARGET is nonzero.
   TARGET is just a suggestion; callers must assume that
   the rtx returned may not be the same as TARGET.
for something unrelated (the value that should be returned), this misbehaves
(in the testcase target is set to a CONST_INT, which has VOIDmode and
reduce_to_bit_field_precision assert checking doesn't like that).
Needed to say that
   If TARGET is CONST0_RTX, it means that the value will be ignored.
but in expand_expr_real_2 does at the start:
  ignore = (target == const0_rtx
            || ((CONVERT_EXPR_CODE_P (code)
                 || code == COND_EXPR || code == VIEW_CONVERT_EXPR)
                && TREE_CODE (type) == VOID_TYPE));

  /* We should be called only if we need the result.  */
  gcc_assert (!ignore);
- so such target is mainly meant for calls and the like in other routines.
Certainly doesn't expect that target changes from not being ignored
initially to ignore later on and other CONST_INT results as well as anything
which is not an object into which anything can be stored.

So, the following patch fixes that by using a more appripriate temporary
for the result, which other code is using.

2024-02-23  Jakub Jelinek  <jakub@redhat.com>

PR rtl-optimization/114054
* expr.cc (expand_expr_real_2) <case MULT_EXPR>: Use
temp variable instead of target parameter for result.

* gcc.dg/bitint-92.c: New test.
gcc/expr.cc
gcc/testsuite/gcc.dg/bitint-92.c [new file with mode: 0644]