From b40b4333470345d905a5a9cc01f82880f18080f7 Mon Sep 17 00:00:00 2001 From: Richard Sandiford Date: Wed, 11 Mar 2026 14:48:04 +0000 Subject: [PATCH] expand: Fix GET_MODE_SIZE/GET_MODE_BITSIZE typo [PR124435] When splitting out store_field_updates_msb_p, r16-7265-ga9e48eca3a6eef accidentally replaced GET_MODE_BITSIZE with GET_MODE_SIZE. A matching rename of to_size to to_bitsize would have overflowed a line, so it seemed worth breaking the endian cases apart. gcc/ PR middle-end/124435 * expr.cc (store_field_updates_msb_p): Use GET_MODE_BITSIZE instead of GET_MODE_SIZE. Handle the two endiannesses separately. gcc/testsuite/ PR middle-end/124435 * gcc.dg/torture/pr124435.c: New test. --- gcc/expr.cc | 6 +++--- gcc/testsuite/gcc.dg/torture/pr124435.c | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/torture/pr124435.c diff --git a/gcc/expr.cc b/gcc/expr.cc index 4d1a6f3dd1c..ba00226c4e7 100644 --- a/gcc/expr.cc +++ b/gcc/expr.cc @@ -5976,9 +5976,9 @@ mem_ref_refers_to_non_mem_p (tree ref) static bool store_field_updates_msb_p (poly_int64 bitpos, poly_int64 bitsize, rtx to_rtx) { - poly_int64 to_size = GET_MODE_SIZE (GET_MODE (to_rtx)); - poly_int64 bitnum = BYTES_BIG_ENDIAN ? to_size - bitsize - bitpos : bitpos; - return maybe_eq (bitnum + bitsize, to_size); + return (BYTES_BIG_ENDIAN + ? maybe_le (bitpos, 0) + : maybe_ge (bitpos + bitsize, GET_MODE_BITSIZE (GET_MODE (to_rtx)))); } /* Expand an assignment that stores the value of FROM into TO. If NONTEMPORAL diff --git a/gcc/testsuite/gcc.dg/torture/pr124435.c b/gcc/testsuite/gcc.dg/torture/pr124435.c new file mode 100644 index 00000000000..d9e1edf9f62 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr124435.c @@ -0,0 +1,18 @@ +/* { dg-do run { target le } } */ + +short c; + +__attribute__((__noipa__)) short +foo (short s) +{ + __builtin_memmove (1 + (char *) &s, &c, 1); + return s >> 10; +} + +int +main () +{ + short x = foo (-6); + if (x) + __builtin_abort(); +}