From b843bcb89519293404bb00d2ed09aae529b54d7f Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Wed, 5 Feb 2020 11:32:37 +0100 Subject: [PATCH] openmp: Avoid ICEs with declare simd; declare simd inbranch [PR93555] 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 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 | 7 +++++++ gcc/omp-simd-clone.c | 12 ++++++++++-- gcc/testsuite/ChangeLog | 9 ++++++++- gcc/testsuite/c-c++-common/gomp/pr93555-1.c | 18 ++++++++++++++++++ gcc/testsuite/c-c++-common/gomp/pr93555-2.c | 16 ++++++++++++++++ gcc/testsuite/gfortran.dg/gomp/pr93555.f90 | 11 +++++++++++ 6 files changed, 70 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/c-c++-common/gomp/pr93555-1.c create mode 100644 gcc/testsuite/c-c++-common/gomp/pr93555-2.c create mode 100644 gcc/testsuite/gfortran.dg/gomp/pr93555.f90 diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 85083e8bc34..aec156eb773 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2020-02-05 Jakub Jelinek + + 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 PR c++/92717 diff --git a/gcc/omp-simd-clone.c b/gcc/omp-simd-clone.c index 8e6cee146b7..71ff0341204 100644 --- a/gcc/omp-simd-clone.c +++ b/gcc/omp-simd-clone.c @@ -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; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 3b2be718c5f..584b111cfd2 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,4 +1,11 @@ -2020-02-05 Jun Ma +2020-02-05 Jakub Jelinek + + 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 * 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 index 00000000000..2eb76a2d9de --- /dev/null +++ b/gcc/testsuite/c-c++-common/gomp/pr93555-1.c @@ -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 index 00000000000..091f5bd5ff1 --- /dev/null +++ b/gcc/testsuite/c-c++-common/gomp/pr93555-2.c @@ -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 index 00000000000..4a97fee07a7 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/gomp/pr93555.f90 @@ -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 -- 2.30.2