diff options
author | Jakub Jelinek <jakub@redhat.com> | 2024-12-14 11:28:25 +0100 |
---|---|---|
committer | Jakub Jelinek <jakub@gcc.gnu.org> | 2024-12-14 11:28:25 +0100 |
commit | 7f4e85a954d24cc30bf85f4040fcd204bd5e23fd (patch) | |
tree | ffbb3eff140796af4c6c682184f006cc82990866 | |
parent | 9537ca5ad9bc23d7e9c446b4a7cbb98f63bddb6a (diff) | |
download | gcc-7f4e85a954d24cc30bf85f4040fcd204bd5e23fd.zip gcc-7f4e85a954d24cc30bf85f4040fcd204bd5e23fd.tar.gz gcc-7f4e85a954d24cc30bf85f4040fcd204bd5e23fd.tar.bz2 |
gimple-fold: Fix the recent ifcombine optimization for _BitInt [PR118023]
The BIT_FIELD_REF verifier has:
if (INTEGRAL_TYPE_P (TREE_TYPE (op))
&& !type_has_mode_precision_p (TREE_TYPE (op)))
{
error ("%qs of non-mode-precision operand", code_name);
return true;
}
check among other things, so one can't extract something out of say
_BitInt(63) or _BitInt(4096).
The new ifcombine optimization happily creates such BIT_FIELD_REFs
and ICEs during their verification.
The following patch fixes that by rejecting those in decode_field_reference.
2024-12-14 Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/118023
* gimple-fold.cc (decode_field_reference): Return NULL_TREE if
inner has non-type_has_mode_precision_p integral type.
* gcc.dg/bitint-119.c: New test.
-rw-r--r-- | gcc/gimple-fold.cc | 4 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/bitint-119.c | 11 |
2 files changed, 14 insertions, 1 deletions
diff --git a/gcc/gimple-fold.cc b/gcc/gimple-fold.cc index e1b4b65..6c11654 100644 --- a/gcc/gimple-fold.cc +++ b/gcc/gimple-fold.cc @@ -7643,7 +7643,9 @@ decode_field_reference (tree *pexp, HOST_WIDE_INT *pbitsize, /* Reject out-of-bound accesses (PR79731). */ || (! AGGREGATE_TYPE_P (TREE_TYPE (inner)) && compare_tree_int (TYPE_SIZE (TREE_TYPE (inner)), - bp + bs) < 0)) + bp + bs) < 0) + || (INTEGRAL_TYPE_P (TREE_TYPE (inner)) + && !type_has_mode_precision_p (TREE_TYPE (inner)))) return NULL_TREE; *pbitsize = bs; diff --git a/gcc/testsuite/gcc.dg/bitint-119.c b/gcc/testsuite/gcc.dg/bitint-119.c new file mode 100644 index 0000000..8283d50 --- /dev/null +++ b/gcc/testsuite/gcc.dg/bitint-119.c @@ -0,0 +1,11 @@ +/* PR tree-optimization/118023 */ +/* { dg-do compile { target bitint } } */ +/* { dg-options "-O2" } */ + +_BitInt(63) b; + +int +foo (void) +{ + return !*(_Complex char *) &b; +} |