[gcc/devel/c++-modules] aarch64: Fix ICE in aarch64_add_offset_1 [PR94121]

Nathan Sidwell nathan@gcc.gnu.org
Thu Mar 19 12:39:10 GMT 2020


https://gcc.gnu.org/g:42bc589e87a326282be2156ddeb18588677c645d

commit 42bc589e87a326282be2156ddeb18588677c645d
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Wed Mar 11 10:54:22 2020 +0100

    aarch64: Fix ICE in aarch64_add_offset_1 [PR94121]
    
    abs_hwi asserts that the argument is not HOST_WIDE_INT_MIN and as the
    (invalid) testcase shows, the function can be called with such an offset.
    The following patch is IMHO minimal fix, absu_hwi unlike abs_hwi allows even
    that value and will return (unsigned HOST_WIDE_INT) HOST_WIDE_INT_MIN
    in that case.  The function then uses moffset in two spots which wouldn't
    care if the value is (unsigned HOST_WIDE_INT) HOST_WIDE_INT_MIN or
    HOST_WIDE_INT_MIN and wouldn't accept it (!moffset and
    aarch64_uimm12_shift (moffset)), then in one spot where the signedness of
    moffset does matter and using unsigned is the right thing -
    moffset < 0x1000000 - and finally has code which will handle even this
    value right; the assembler doesn't really care for DImode immediates if
            mov     x1, -9223372036854775808
    or
            mov     x1, 9223372036854775808
    is used and similarly it doesn't matter if we add or sub it in DImode.
    
    2020-03-11  Jakub Jelinek  <jakub@redhat.com>
    
            PR target/94121
            * config/aarch64/aarch64.c (aarch64_add_offset_1): Use absu_hwi
            instead of abs_hwi, change moffset type to unsigned HOST_WIDE_INT.
    
            * gcc.dg/pr94121.c: New test.

Diff:
---
 gcc/ChangeLog                  |  4 ++++
 gcc/config/aarch64/aarch64.c   |  2 +-
 gcc/testsuite/ChangeLog        |  3 +++
 gcc/testsuite/gcc.dg/pr94121.c | 16 ++++++++++++++++
 4 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index e4b74dd1f06..1fc6ff36c84 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,5 +1,9 @@
 2020-03-11  Jakub Jelinek  <jakub@redhat.com>
 
+	PR target/94121
+	* config/aarch64/aarch64.c (aarch64_add_offset_1): Use absu_hwi
+	instead of abs_hwi, change moffset type to unsigned HOST_WIDE_INT.
+
 	PR bootstrap/93962
 	* value-prof.c (dump_histogram_value): Use abs_hwi instead of
 	std::abs.
diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c
index 4b9747b4c5e..c320d5ba51d 100644
--- a/gcc/config/aarch64/aarch64.c
+++ b/gcc/config/aarch64/aarch64.c
@@ -3713,7 +3713,7 @@ aarch64_add_offset_1 (scalar_int_mode mode, rtx dest,
   gcc_assert (emit_move_imm || temp1 != NULL_RTX);
   gcc_assert (temp1 == NULL_RTX || !reg_overlap_mentioned_p (temp1, src));
 
-  HOST_WIDE_INT moffset = abs_hwi (offset);
+  unsigned HOST_WIDE_INT moffset = absu_hwi (offset);
   rtx_insn *insn;
 
   if (!moffset)
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 3a4acce6746..af94cb47ae6 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,5 +1,8 @@
 2020-03-11  Jakub Jelinek  <jakub@redhat.com>
 
+	PR target/94121
+	* gcc.dg/pr94121.c: New test.
+
 	PR middle-end/94111
 	* gcc.dg/dfp/pr94111.c: New test.
 
diff --git a/gcc/testsuite/gcc.dg/pr94121.c b/gcc/testsuite/gcc.dg/pr94121.c
new file mode 100644
index 00000000000..2a4261ae02d
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr94121.c
@@ -0,0 +1,16 @@
+/* PR target/94121 */
+/* { dg-do compile { target pie } } */
+/* { dg-options "-O2 -fpie -w" } */
+
+#define DIFF_MAX __PTRDIFF_MAX__
+#define DIFF_MIN (-DIFF_MAX - 1)
+
+extern void foo (char *);
+extern char v[];
+
+void
+bar (void)
+{
+  char *p = v;
+  foo (&p[DIFF_MIN]);
+}


More information about the Gcc-cvs mailing list