aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2023-12-01 10:55:49 +0100
committerJakub Jelinek <jakub@redhat.com>2023-12-01 10:55:49 +0100
commit9bfebcb1b7ae4e7160644f2104424d6bab4a23f7 (patch)
treead04c76580cdd98d9a4071bb6cf0be088f8d1364 /gcc
parentb506834e7fa939e43f784d417f0e9b4ded91ebd2 (diff)
downloadgcc-9bfebcb1b7ae4e7160644f2104424d6bab4a23f7.zip
gcc-9bfebcb1b7ae4e7160644f2104424d6bab4a23f7.tar.gz
gcc-9bfebcb1b7ae4e7160644f2104424d6bab4a23f7.tar.bz2
lower-bitint: Fix up handle_operand_addr for 0 constants [PR112771]
handle_operand_addr for INTEGER_CSTs uses wi::min_precision (UNSIGNED for non-negative constants, SIGNED for negative ones) and from that computes mp as minimum number of limbs which can represent that value, and in some cases creates a test BITINT_TYPE with that precision to categorize it and decide based on that what types to use on the constant emitted into memory. For the actual precisions (what will be passed to libgcc) it actually already uses MAX/MIN to adjust the corner cases: *prec = MAX (min_prec, 1); ... *prec = MIN ((int) -min_prec, -2); but for integer_zerop min_prec will be 0, mp = CEIL (min_prec, limb_prec) * limb_prec; will be also 0 and we ICE trying to build unsigned BITINT_TYPE with 0 precision. Fixed thusly by noting even 0 has to be encoded at least as one limb. 2023-12-01 Jakub Jelinek <jakub@redhat.com> PR middle-end/112771 * gimple-lower-bitint.cc (bitint_large_huge::handle_operand_addr): Use mp = 1 if it is zero. * gcc.dg/bitint-44.c: New test.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/gimple-lower-bitint.cc2
-rw-r--r--gcc/testsuite/gcc.dg/bitint-44.c10
2 files changed, 12 insertions, 0 deletions
diff --git a/gcc/gimple-lower-bitint.cc b/gcc/gimple-lower-bitint.cc
index 7c8c640..d0e24cb 100644
--- a/gcc/gimple-lower-bitint.cc
+++ b/gcc/gimple-lower-bitint.cc
@@ -2179,6 +2179,8 @@ bitint_large_huge::handle_operand_addr (tree op, gimple *stmt,
*prec = MIN ((int) -min_prec, -2);
}
mp = CEIL (min_prec, limb_prec) * limb_prec;
+ if (mp == 0)
+ mp = 1;
if (mp >= (unsigned) TYPE_PRECISION (TREE_TYPE (op)))
type = TREE_TYPE (op);
else
diff --git a/gcc/testsuite/gcc.dg/bitint-44.c b/gcc/testsuite/gcc.dg/bitint-44.c
new file mode 100644
index 0000000..d1f34d0
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/bitint-44.c
@@ -0,0 +1,10 @@
+/* PR middle-end/112771 */
+/* { dg-do compile { target bitint575 } } */
+/* { dg-options "-std=c23" } */
+
+_BitInt(575)
+foo (_BitInt(575) a)
+{
+ a /= 0; /* { dg-warning "division by zero" } */
+ return a;
+}