public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r10-9068] arm: correctly handle negating INT_MIN in arm_split_atomic_op [PR97534]
@ 2020-11-24 16:51 Richard Earnshaw
  0 siblings, 0 replies; only message in thread
From: Richard Earnshaw @ 2020-11-24 16:51 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:dd2c4e4e97331b1b3d9081191d14f8967d73e31c

commit r10-9068-gdd2c4e4e97331b1b3d9081191d14f8967d73e31c
Author: Richard Earnshaw <rearnsha@arm.com>
Date:   Tue Nov 24 16:21:17 2020 +0000

    arm: correctly handle negating INT_MIN in arm_split_atomic_op [PR97534]
    
    arm_split_atomic_op handles subtracting a constant by converting it
    into addition of the negated constant.  But if the type of the operand
    is int and the constant is -1 we currently end up generating invalid
    RTL which can lead to an abort later on.
    
    The problem is that in a HOST_WIDE_INT, INT_MIN is represented as
    0xffffffff80000000 and the negation of this is 0x0000000080000000, but
    that's not a valid constant for use in SImode operations.
    
    The fix is straight-forward which is to use gen_int_mode rather than
    simply GEN_INT.  This knows how to correctly sign-extend the negated
    constant when this is needed.
    
    gcc/
            PR target/97534
            * config/arm/arm.c (arm_split_atomic_op): Use gen_int_mode when
            negating a const_int.
    gcc/testsuite
            * gcc.dg/pr97534.c: New test.

Diff:
---
 gcc/config/arm/arm.c           | 2 +-
 gcc/testsuite/gcc.dg/pr97534.c | 9 +++++++++
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c
index 99b1e926dc3..b4d7b5bc507 100644
--- a/gcc/config/arm/arm.c
+++ b/gcc/config/arm/arm.c
@@ -30582,7 +30582,7 @@ arm_split_atomic_op (enum rtx_code code, rtx old_out, rtx new_out, rtx mem,
     case MINUS:
       if (CONST_INT_P (value))
 	{
-	  value = GEN_INT (-INTVAL (value));
+	  value = gen_int_mode (-INTVAL (value), wmode);
 	  code = PLUS;
 	}
       /* FALLTHRU */
diff --git a/gcc/testsuite/gcc.dg/pr97534.c b/gcc/testsuite/gcc.dg/pr97534.c
new file mode 100644
index 00000000000..b363a322aa5
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr97534.c
@@ -0,0 +1,9 @@
+/* PR target/97534 - ICE in decompose on arm*-*-*.  */
+/* { dg-do compile } */
+/* { dg-options "-std=c11 -O2 -g" } */
+
+int f (int a)
+{
+  int b;
+  __atomic_fetch_sub(&b, (int)(-__INT_MAX__ - 1), (int)0);
+}


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-11-24 16:51 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-24 16:51 [gcc r10-9068] arm: correctly handle negating INT_MIN in arm_split_atomic_op [PR97534] Richard Earnshaw

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).