openmp: Avoid ICEs with declare simd; declare simd inbranch [PR93555]
authorJakub Jelinek <jakub@redhat.com>
Wed, 5 Feb 2020 10:32:37 +0000 (11:32 +0100)
committerJakub Jelinek <jakub@redhat.com>
Wed, 5 Feb 2020 10:32:37 +0000 (11:32 +0100)
The testcases ICE because when processing the declare simd inbranch,
we don't create the i == 0 clone as it already exists, which means
clone_info->nargs is not adjusted, but we then rely on it being adjusted
when trying other clones.

2020-02-05  Jakub Jelinek  <jakub@redhat.com>

PR middle-end/93555
* omp-simd-clone.c (expand_simd_clones): If simd_clone_mangle or
simd_clone_create failed when i == 0, adjust clone->nargs by
clone->inbranch.

* c-c++-common/gomp/pr93555-1.c: New test.
* c-c++-common/gomp/pr93555-2.c: New test.
* gfortran.dg/gomp/pr93555.f90: New test.

gcc/ChangeLog
gcc/omp-simd-clone.c
gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/gomp/pr93555-1.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/gomp/pr93555-2.c [new file with mode: 0644]
gcc/testsuite/gfortran.dg/gomp/pr93555.f90 [new file with mode: 0644]

index 85083e8bc34a0ab32135b2872c50217c5cad52d2..aec156eb7737f1f93e7ebe9333bce5932fa1dadc 100644 (file)
@@ -1,3 +1,10 @@
+2020-02-05  Jakub Jelinek  <jakub@redhat.com>
+
+       PR middle-end/93555
+       * omp-simd-clone.c (expand_simd_clones): If simd_clone_mangle or
+       simd_clone_create failed when i == 0, adjust clone->nargs by
+       clone->inbranch.
+
 2020-02-05  Martin Liska  <mliska@suse.cz>
 
        PR c++/92717
index 8e6cee146b79ebe74eb33cc199b4f450fa449238..71ff03412044406a9e3f804c64cc782a1d7d590a 100644 (file)
@@ -1713,14 +1713,22 @@ expand_simd_clones (struct cgraph_node *node)
             already.  */
          tree id = simd_clone_mangle (node, clone);
          if (id == NULL_TREE)
-           continue;
+           {
+             if (i == 0)
+               clone->nargs += clone->inbranch;
+             continue;
+           }
 
          /* Only when we are sure we want to create the clone actually
             clone the function (or definitions) or create another
             extern FUNCTION_DECL (for prototypes without definitions).  */
          struct cgraph_node *n = simd_clone_create (node);
          if (n == NULL)
-           continue;
+           {
+             if (i == 0)
+               clone->nargs += clone->inbranch;
+             continue;
+           }
 
          n->simdclone = clone;
          clone->origin = node;
index 3b2be718c5fe36423d51a2375c254266653ba660..584b111cfd23cbc67318e26fffef21333363467b 100644 (file)
@@ -1,4 +1,11 @@
-2020-02-05  Jun Ma <JunMa@linux.alibaba.com>
+2020-02-05  Jakub Jelinek  <jakub@redhat.com>
+
+       PR middle-end/93555
+       * c-c++-common/gomp/pr93555-1.c: New test.
+       * c-c++-common/gomp/pr93555-2.c: New test.
+       * gfortran.dg/gomp/pr93555.f90: New test.
+
+2020-02-05  Jun Ma  <JunMa@linux.alibaba.com>
 
        * g++.dg/coroutines/co-await-14-return-ref-to-auto.C: New test.
 
diff --git a/gcc/testsuite/c-c++-common/gomp/pr93555-1.c b/gcc/testsuite/c-c++-common/gomp/pr93555-1.c
new file mode 100644 (file)
index 0000000..2eb76a2
--- /dev/null
@@ -0,0 +1,18 @@
+/* PR middle-end/93555 */
+/* { dg-do compile } */
+
+#pragma omp declare simd
+#pragma omp declare simd inbranch
+int
+foo (int x)
+{
+  return x;
+}
+
+#pragma omp declare simd inbranch
+#pragma omp declare simd
+int
+bar (int x)
+{
+  return x;
+}
diff --git a/gcc/testsuite/c-c++-common/gomp/pr93555-2.c b/gcc/testsuite/c-c++-common/gomp/pr93555-2.c
new file mode 100644 (file)
index 0000000..091f5bd
--- /dev/null
@@ -0,0 +1,16 @@
+/* PR middle-end/93555 */
+/* { dg-do compile } */
+
+#pragma omp declare simd
+#pragma omp declare simd inbranch
+void
+foo (void)
+{
+}
+
+#pragma omp declare simd inbranch
+#pragma omp declare simd
+void
+bar (void)
+{
+}
diff --git a/gcc/testsuite/gfortran.dg/gomp/pr93555.f90 b/gcc/testsuite/gfortran.dg/gomp/pr93555.f90
new file mode 100644 (file)
index 0000000..4a97fee
--- /dev/null
@@ -0,0 +1,11 @@
+! PR middle-end/93555
+! { dg-do compile }
+
+subroutine foo
+  !$omp declare simd(foo)
+  !$omp declare simd(foo) inbranch
+end
+subroutine bar
+  !$omp declare simd(bar) inbranch
+  !$omp declare simd(bar)
+end