testsuite: fix ASAN errors in i386.exp tests

Message ID e1789ec2-3bce-f2cf-c207-18e30a1813c2@suse.cz
State New
Headers
Series testsuite: fix ASAN errors in i386.exp tests |

Commit Message

Martin Liška Dec. 14, 2021, 3:28 p.m. UTC
  The patch fixes various tests in i386.exp that fail with:

make check -k RUNTESTFLAGS="i386.exp --target_board=unix/-fsanitize=address"

Survives i386.exp w/o sanitizer.

Ready for master?
Thanks,
Martin

gcc/testsuite/ChangeLog:

	* gcc.target/i386/avx2-i32gatherpd256-4.c: Fix ASAN errors.
	* gcc.target/i386/avx2-i32gatherq256-4.c: Likewise.
	* gcc.target/i386/avx2-i64gatherpd256-4.c: Likewise.
	* gcc.target/i386/avx2-i64gatherq256-4.c: Likewise.
	* gcc.target/i386/avx2-vpabsb256-2.c: Likewise.
	* gcc.target/i386/avx2-vpabsd256-2.c: Likewise.
	* gcc.target/i386/avx2-vpabsw256-2.c: Likewise.
	* gcc.target/i386/avx256-unaligned-load-7.c: Likewise.
	* gcc.target/i386/avx256-unaligned-store-7.c: Likewise.
	* gcc.target/i386/pr64291-1.c: Likewise.
---
  .../gcc.target/i386/avx2-i32gatherpd256-4.c        | 14 +++++++++-----
  .../gcc.target/i386/avx2-i32gatherq256-4.c         | 14 +++++++++-----
  .../gcc.target/i386/avx2-i64gatherpd256-4.c        | 14 +++++++++-----
  .../gcc.target/i386/avx2-i64gatherq256-4.c         | 14 +++++++++-----
  gcc/testsuite/gcc.target/i386/avx2-vpabsb256-2.c   |  2 +-
  gcc/testsuite/gcc.target/i386/avx2-vpabsd256-2.c   |  2 +-
  gcc/testsuite/gcc.target/i386/avx2-vpabsw256-2.c   |  2 +-
  .../gcc.target/i386/avx256-unaligned-load-7.c      |  8 ++++----
  .../gcc.target/i386/avx256-unaligned-store-7.c     |  4 ++--
  gcc/testsuite/gcc.target/i386/pr64291-1.c          |  2 +-
  10 files changed, 46 insertions(+), 30 deletions(-)
  

Comments

Martin Liška Jan. 3, 2022, 11:44 a.m. UTC | #1
On 12/14/21 16:28, Martin Liška wrote:
> Ready for master?

I'm going to install this as it's quite obvious.

Martin
  

Patch

diff --git a/gcc/testsuite/gcc.target/i386/avx2-i32gatherpd256-4.c b/gcc/testsuite/gcc.target/i386/avx2-i32gatherpd256-4.c
index f24acbd7fe1..17b0c40e4d4 100644
--- a/gcc/testsuite/gcc.target/i386/avx2-i32gatherpd256-4.c
+++ b/gcc/testsuite/gcc.target/i386/avx2-i32gatherpd256-4.c
@@ -25,15 +25,19 @@  avx2_test (void)
    int i;
    union128i_d idx;
    union256d res, src, mask;
-  double s1[4], res_ref[4] = { 0 };
+  double s1[16], res_ref[4] = { 0 };
+  double *s1_ptr = s1 + 8;
  
-  for (i = 0; i < 4; ++i)
+  for (i = 0; i < ARRAY_SIZE (s1); i++)
      {
        /* Set some stuff */
        s1[i] = 2.718281828459045 * (i + 1) * (i + 2);
+    }
  
+  for (i = 0; i < 4; ++i)
+    {
        /* Set src as something different from s1 */
-      src.a[i] = -s1[i];
+      src.a[i] = -s1_ptr[i];
  
        /* Mask out evens */
        ((long long *) mask.a)[i] = i % 2 ? 0 : -1;
@@ -43,9 +47,9 @@  avx2_test (void)
        idx.a[i] = (16 - (i + 1) * 8) >> 1;
      }
  
-  res.x = _mm256_mask_i32gather_pd (src.x, s1, idx.x, mask.x, 2);
+  res.x = _mm256_mask_i32gather_pd (src.x, s1_ptr, idx.x, mask.x, 2);
  
-  compute_i32gatherpd256 (src.a, s1, idx.a, mask.a, 2, res_ref);
+  compute_i32gatherpd256 (src.a, s1_ptr, idx.a, mask.a, 2, res_ref);
  
    if (check_union256d (res, res_ref) != 0)
      abort ();
diff --git a/gcc/testsuite/gcc.target/i386/avx2-i32gatherq256-4.c b/gcc/testsuite/gcc.target/i386/avx2-i32gatherq256-4.c
index 3eab9be5c96..77ebf1fc198 100644
--- a/gcc/testsuite/gcc.target/i386/avx2-i32gatherq256-4.c
+++ b/gcc/testsuite/gcc.target/i386/avx2-i32gatherq256-4.c
@@ -25,15 +25,19 @@  avx2_test (void)
    long long i;
    union128i_d idx;
    union256i_q res, src, mask;
-  long long s1[4], res_ref[4] = { 0 };
+  long long s1[16], res_ref[4] = { 0 };
+  long long *s1_ptr = s1 + 8;
  
-  for (i = 0; i < 4; ++i)
+  for (i = 0; i < ARRAY_SIZE (s1); i++)
      {
        /* Set some stuff */
        s1[i] = 1983 * (i + 1) * (i + 2);
+    }
  
+  for (i = 0; i < 4; ++i)
+    {
        /* Set src as something different from s1 */
-      src.a[i] = -s1[i];
+      src.a[i] = -s1_ptr[i];
  
        /* Mask out evens */
        mask.a[i] = i % 2 ? 0 : -1;
@@ -44,10 +48,10 @@  avx2_test (void)
      }
  
    res.x = _mm256_mask_i32gather_epi64 (src.x,
-				       (long long int *) s1,
+				       (long long int *) s1_ptr,
  				       idx.x, mask.x, 2);
  
-  compute_i32gatherpd256 (src.a, s1, idx.a, mask.a, 2, res_ref);
+  compute_i32gatherpd256 (src.a, s1_ptr, idx.a, mask.a, 2, res_ref);
  
    if (check_union256i_q (res, res_ref) != 0)
      abort ();
diff --git a/gcc/testsuite/gcc.target/i386/avx2-i64gatherpd256-4.c b/gcc/testsuite/gcc.target/i386/avx2-i64gatherpd256-4.c
index 09a5f8a14e0..cf94256e1da 100644
--- a/gcc/testsuite/gcc.target/i386/avx2-i64gatherpd256-4.c
+++ b/gcc/testsuite/gcc.target/i386/avx2-i64gatherpd256-4.c
@@ -25,15 +25,19 @@  avx2_test (void)
    int i;
    union256i_q idx;
    union256d res, src, mask;
-  double s1[4], res_ref[4] = { 0 };
+  double s1[16], res_ref[4] = { 0 };
+  double *s1_ptr = s1 + 8;
  
-  for (i = 0; i < 4; ++i)
+  for (i = 0; i < ARRAY_SIZE (s1); i++)
      {
        /* Set some stuff */
        s1[i] = 2.718281828459045 * (i + 1) * (i + 2);
+    }
  
+  for (i = 0; i < 4; ++i)
+    {
        /* Set src as something different from s1 */
-      src.a[i] = -s1[i];
+      src.a[i] = -s1_ptr[i];
  
        /* Mask out evens */
        ((long long *) mask.a)[i] = i % 2 ? 0 : -1;
@@ -43,9 +47,9 @@  avx2_test (void)
        idx.a[i] = (16 - (i + 1) * 8) >> 1;
      }
  
-  res.x = _mm256_mask_i64gather_pd (src.x, s1, idx.x, mask.x, 2);
+  res.x = _mm256_mask_i64gather_pd (src.x, s1_ptr, idx.x, mask.x, 2);
  
-  compute_i64gatherpd256 (src.a, s1, idx.a, mask.a, 2, res_ref);
+  compute_i64gatherpd256 (src.a, s1_ptr, idx.a, mask.a, 2, res_ref);
  
    if (check_union256d (res, res_ref) != 0)
      abort ();
diff --git a/gcc/testsuite/gcc.target/i386/avx2-i64gatherq256-4.c b/gcc/testsuite/gcc.target/i386/avx2-i64gatherq256-4.c
index 355c8c2b062..396ffb45961 100644
--- a/gcc/testsuite/gcc.target/i386/avx2-i64gatherq256-4.c
+++ b/gcc/testsuite/gcc.target/i386/avx2-i64gatherq256-4.c
@@ -26,15 +26,19 @@  avx2_test (void)
    long long i;
    union256i_q idx;
    union256i_q res, src, mask;
-  long long s1[4], res_ref[4] = { 0 };
+  long long s1[16], res_ref[4] = { 0 };
+  long long *s1_ptr = s1 + 8;
  
-  for (i = 0; i < 4; ++i)
+  for (i = 0; i < ARRAY_SIZE (s1); i++)
      {
        /* Set some stuff */
        s1[i] = 1983 * (i + 1) * (i + 2);
+    }
  
+  for (i = 0; i < 4; ++i)
+    {
        /* Set src as something different from s1 */
-      src.a[i] = -s1[i];
+      src.a[i] = -s1_ptr[i];
  
        /* Mask out evens */
        ((long long *) mask.a)[i] = i % 2 ? 0 : -1;
@@ -45,10 +49,10 @@  avx2_test (void)
      }
  
    res.x = _mm256_mask_i64gather_epi64 (src.x,
-				       (long long int *) s1,
+				       (long long int *) s1_ptr,
  				       idx.x, mask.x, 2);
  
-  compute_i64gatherq256 (src.a, s1, idx.a, mask.a, 2, res_ref);
+  compute_i64gatherq256 (src.a, s1_ptr, idx.a, mask.a, 2, res_ref);
  
    if (check_union256i_q (res, res_ref) != 0)
      abort ();
diff --git a/gcc/testsuite/gcc.target/i386/avx2-vpabsb256-2.c b/gcc/testsuite/gcc.target/i386/avx2-vpabsb256-2.c
index 05db8a40723..9b732af50c8 100644
--- a/gcc/testsuite/gcc.target/i386/avx2-vpabsb256-2.c
+++ b/gcc/testsuite/gcc.target/i386/avx2-vpabsb256-2.c
@@ -28,7 +28,7 @@  avx2_test (void)
  
    union256i_b s, d;
  
-  for (i = 0; i < 256; ++i)
+  for (i = 0; i < 256 - 7; ++i)
      {
        /* Recompute the results for 256-bits */
        compute_pabs256 (&vals[i], ck);
diff --git a/gcc/testsuite/gcc.target/i386/avx2-vpabsd256-2.c b/gcc/testsuite/gcc.target/i386/avx2-vpabsd256-2.c
index 4c88024b58a..caf1a580674 100644
--- a/gcc/testsuite/gcc.target/i386/avx2-vpabsd256-2.c
+++ b/gcc/testsuite/gcc.target/i386/avx2-vpabsd256-2.c
@@ -27,7 +27,7 @@  avx2_test (void)
  
    union256i_d s, d;
  
-  for (i = 0; i < 256; ++i)
+  for (i = 0; i < 256 - 7; ++i)
      {
        /* Recompute the results for 256-bits */
        compute_pabs256 (&vals[i], ck);
diff --git a/gcc/testsuite/gcc.target/i386/avx2-vpabsw256-2.c b/gcc/testsuite/gcc.target/i386/avx2-vpabsw256-2.c
index fa4efd2984b..299323de3d6 100644
--- a/gcc/testsuite/gcc.target/i386/avx2-vpabsw256-2.c
+++ b/gcc/testsuite/gcc.target/i386/avx2-vpabsw256-2.c
@@ -28,7 +28,7 @@  avx2_test (void)
  
    union256i_w s, d;
  
-  for (i = 0; i < 256; ++i)
+  for (i = 0; i < 256 - 7; ++i)
      {
        /* Using only first 2 bytes of int */
        /* Recompute the results for 256-bits */
diff --git a/gcc/testsuite/gcc.target/i386/avx256-unaligned-load-7.c b/gcc/testsuite/gcc.target/i386/avx256-unaligned-load-7.c
index 4c6054c0ff6..de30ddba348 100644
--- a/gcc/testsuite/gcc.target/i386/avx256-unaligned-load-7.c
+++ b/gcc/testsuite/gcc.target/i386/avx256-unaligned-load-7.c
@@ -16,10 +16,10 @@  __attribute__ ((noinline))
  void
  foo (void)
  {
-  mp = (char **) malloc (N);
-  lp = (char **) malloc (N);
-  ep = (char **) malloc (N);
-  fp = (char **) malloc (N);
+  mp = (char **) malloc (N * sizeof (char **));
+  lp = (char **) malloc (N * sizeof (char **));
+  ep = (char **) malloc (N * sizeof (char **));
+  fp = (char **) malloc (N * sizeof (char **));
  }
  
  void
diff --git a/gcc/testsuite/gcc.target/i386/avx256-unaligned-store-7.c b/gcc/testsuite/gcc.target/i386/avx256-unaligned-store-7.c
index 99a0c719753..2752e7fbec1 100644
--- a/gcc/testsuite/gcc.target/i386/avx256-unaligned-store-7.c
+++ b/gcc/testsuite/gcc.target/i386/avx256-unaligned-store-7.c
@@ -14,8 +14,8 @@  __attribute__ ((noinline))
  void
  foo (void)
  {
-  ep = (char **) malloc (N);
-  fp = (char **) malloc (N);
+  ep = (char **) malloc (N * sizeof (char **));
+  fp = (char **) malloc (N * sizeof (char **));
  }
  
  void
diff --git a/gcc/testsuite/gcc.target/i386/pr64291-1.c b/gcc/testsuite/gcc.target/i386/pr64291-1.c
index 1d3a3809242..85f1e04e724 100644
--- a/gcc/testsuite/gcc.target/i386/pr64291-1.c
+++ b/gcc/testsuite/gcc.target/i386/pr64291-1.c
@@ -24,7 +24,7 @@  int main ()
    f (n);
    h (d);
    qp = (unsigned long*)__builtin_alloca(4099*8) + 1;
-  dnp = (unsigned long*)__builtin_alloca (2049*8);
+  dnp = (unsigned long*)__builtin_alloca (2049*8) + 1;
    alloc = 1;
    for (test = 0; test < 1; test++)
      {