From 21925ac173495dad58a5ed0293ceb0203f849a51 Mon Sep 17 00:00:00 2001 From: Alexander Monakov Date: Mon, 25 Jun 2018 20:44:15 +0300 Subject: [PATCH] gcc_qsort: avoid overlapping memcpy (PR 86311) PR middle-end/86311 * sort.cc (REORDER_23): Avoid memcpy with same destination and source. (REORDER_45): Likewise. From-SVN: r262092 --- gcc/ChangeLog | 6 ++++++ gcc/sort.cc | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index ceec833bb70..a837cae287e 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2018-06-25 Alexander Monakov + + PR middle-end/86311 + * sort.cc (REORDER_23): Avoid memcpy with same destination and source. + (REORDER_45): Likewise. + 2018-06-25 Jeff Law * config/v850/v850.md (divmodhi4): Make sure to sign extend the diff --git a/gcc/sort.cc b/gcc/sort.cc index a48a477d4e8..293e2058f89 100644 --- a/gcc/sort.cc +++ b/gcc/sort.cc @@ -69,7 +69,7 @@ do { \ memcpy (&t1, e1 + OFFSET, sizeof (TYPE)); \ char *out = c->out + OFFSET; \ if (likely (c->n == 3)) \ - memcpy (out + 2*STRIDE, e2 + OFFSET, sizeof (TYPE)); \ + memmove (out + 2*STRIDE, e2 + OFFSET, sizeof (TYPE));\ memcpy (out, &t0, sizeof (TYPE)); out += STRIDE; \ memcpy (out, &t1, sizeof (TYPE)); \ } while (0) @@ -101,7 +101,7 @@ do { \ memcpy (&t3, e3 + OFFSET, sizeof (TYPE)); \ char *out = c->out + OFFSET; \ if (likely (c->n == 5)) \ - memcpy (out + 4*STRIDE, e4 + OFFSET, sizeof (TYPE)); \ + memmove (out + 4*STRIDE, e4 + OFFSET, sizeof (TYPE));\ memcpy (out, &t0, sizeof (TYPE)); out += STRIDE; \ memcpy (out, &t1, sizeof (TYPE)); out += STRIDE; \ memcpy (out, &t2, sizeof (TYPE)); out += STRIDE; \ -- 2.30.2