From: Jakub Jelinek Date: Thu, 24 Jan 2019 19:16:21 +0000 (+0100) Subject: re PR c++/88976 (ICE in fold_convert_loc, at fold-const.c:2552) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=e21c4491293763b5dc61664b6a2292c3a8fc8ae1;p=gcc.git re PR c++/88976 (ICE in fold_convert_loc, at fold-const.c:2552) PR c++/88976 * c-typeck.c (c_finish_omp_cancel): Diagnose more than one if on #pragma omp cancel with different modifiers. * semantics.c (finish_omp_cancel): Diagnose more than one if on #pragma omp cancel with different modifiers. Use maybe_convert_cond when not in template or build_x_binary_op otherwise. * c-c++-common/gomp/cancel-2.c: New test. * gcc.dg/gomp/cancel-1.c: New test. * g++.dg/gomp/cancel-1.C: New test. * g++.dg/gomp/cancel-2.C: New test. * g++.dg/gomp/cancel-3.C: New test. From-SVN: r268245 --- diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index fe83d69de87..32c77f9360b 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,9 @@ +2019-01-24 Jakub Jelinek + + PR c++/88976 + * c-typeck.c (c_finish_omp_cancel): Diagnose more than one if + on #pragma omp cancel with different modifiers. + 2019-01-18 H.J. Lu PR c/51628 diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c index cbd612c4fb9..48112006f04 100644 --- a/gcc/c/c-typeck.c +++ b/gcc/c/c-typeck.c @@ -12766,6 +12766,18 @@ c_finish_omp_cancel (location_t loc, tree clauses) && OMP_CLAUSE_IF_MODIFIER (ifc) != VOID_CST) error_at (OMP_CLAUSE_LOCATION (ifc), "expected % % clause modifier"); + else + { + tree ifc2 = omp_find_clause (OMP_CLAUSE_CHAIN (ifc), OMP_CLAUSE_IF); + if (ifc2 != NULL_TREE) + { + gcc_assert (OMP_CLAUSE_IF_MODIFIER (ifc) == VOID_CST + && OMP_CLAUSE_IF_MODIFIER (ifc2) != ERROR_MARK + && OMP_CLAUSE_IF_MODIFIER (ifc2) != VOID_CST); + error_at (OMP_CLAUSE_LOCATION (ifc2), + "expected % % clause modifier"); + } + } tree type = TREE_TYPE (OMP_CLAUSE_IF_EXPR (ifc)); ifc = fold_build2_loc (OMP_CLAUSE_LOCATION (ifc), NE_EXPR, diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 58acbf0a241..99d43c9d7a4 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,11 @@ +2019-01-24 Jakub Jelinek + + PR c++/88976 + * semantics.c (finish_omp_cancel): Diagnose more than one if + on #pragma omp cancel with different modifiers. Use + maybe_convert_cond when not in template or build_x_binary_op + otherwise. + 2019-01-23 Marek Polacek PR c++/88757 - qualified name treated wrongly as type. diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index e654750d249..72191395b47 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -9055,11 +9055,26 @@ finish_omp_cancel (tree clauses) && OMP_CLAUSE_IF_MODIFIER (ifc) != VOID_CST) error_at (OMP_CLAUSE_LOCATION (ifc), "expected % % clause modifier"); + else + { + tree ifc2 = omp_find_clause (OMP_CLAUSE_CHAIN (ifc), OMP_CLAUSE_IF); + if (ifc2 != NULL_TREE) + { + gcc_assert (OMP_CLAUSE_IF_MODIFIER (ifc) == VOID_CST + && OMP_CLAUSE_IF_MODIFIER (ifc2) != ERROR_MARK + && OMP_CLAUSE_IF_MODIFIER (ifc2) != VOID_CST); + error_at (OMP_CLAUSE_LOCATION (ifc2), + "expected % % clause modifier"); + } + } - tree type = TREE_TYPE (OMP_CLAUSE_IF_EXPR (ifc)); - ifc = fold_build2_loc (OMP_CLAUSE_LOCATION (ifc), NE_EXPR, - boolean_type_node, OMP_CLAUSE_IF_EXPR (ifc), - build_zero_cst (type)); + if (!processing_template_decl) + ifc = maybe_convert_cond (OMP_CLAUSE_IF_EXPR (ifc)); + else + ifc = build_x_binary_op (OMP_CLAUSE_LOCATION (ifc), NE_EXPR, + OMP_CLAUSE_IF_EXPR (ifc), ERROR_MARK, + integer_zero_node, ERROR_MARK, + NULL, tf_warning_or_error); } else ifc = boolean_true_node; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 75467a3f84f..809c952e30a 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,12 @@ +2019-01-24 Jakub Jelinek + + PR c++/88976 + * c-c++-common/gomp/cancel-2.c: New test. + * gcc.dg/gomp/cancel-1.c: New test. + * g++.dg/gomp/cancel-1.C: New test. + * g++.dg/gomp/cancel-2.C: New test. + * g++.dg/gomp/cancel-3.C: New test. + 2019-01-24 Jakub Jelinek PR tree-optimization/89027 diff --git a/gcc/testsuite/c-c++-common/gomp/cancel-2.c b/gcc/testsuite/c-c++-common/gomp/cancel-2.c new file mode 100644 index 00000000000..bd016c231aa --- /dev/null +++ b/gcc/testsuite/c-c++-common/gomp/cancel-2.c @@ -0,0 +1,15 @@ +/* { dg-do compile } */ + +void +foo (void) +{ + #pragma omp parallel + { + #pragma omp cancel parallel if (1) if (1) /* { dg-error "too many 'if' clauses without modifier" } */ + #pragma omp cancel parallel if (cancel: 1) if (cancel: 1) /* { dg-error "too many 'if' clauses with 'cancel' modifier" } */ + #pragma omp cancel parallel if (cancel: 1) if (1) /* { dg-error "if any 'if' clause has modifier, then all 'if' clauses have to use modifier" } */ + #pragma omp cancel parallel if (cancel: 1) if (parallel: 1) /* { dg-error "expected 'cancel' 'if' clause modifier" } */ + #pragma omp cancel parallel if (1) if (cancel: 1) /* { dg-error "if any 'if' clause has modifier, then all 'if' clauses have to use modifier" } */ + #pragma omp cancel parallel if (parallel: 1) if (cancel: 1) /* { dg-error "expected 'cancel' 'if' clause modifier" } */ + } +} diff --git a/gcc/testsuite/g++.dg/gomp/cancel-1.C b/gcc/testsuite/g++.dg/gomp/cancel-1.C new file mode 100644 index 00000000000..a6b1167856f --- /dev/null +++ b/gcc/testsuite/g++.dg/gomp/cancel-1.C @@ -0,0 +1,26 @@ +// PR c++/88976 +// { dg-do compile } + +template void +foo (T x) +{ +#pragma omp parallel + { + #pragma omp cancel parallel if (x) + } +#pragma omp parallel + { + #pragma omp cancel parallel if (1 == 1) + } +} + +void +bar (int x, double y, long long z) +{ + foo (0); + foo (1LL); + foo (1.25); + foo (x); + foo (y); + foo (z); +} diff --git a/gcc/testsuite/g++.dg/gomp/cancel-2.C b/gcc/testsuite/g++.dg/gomp/cancel-2.C new file mode 100644 index 00000000000..c9269e7b326 --- /dev/null +++ b/gcc/testsuite/g++.dg/gomp/cancel-2.C @@ -0,0 +1,20 @@ +// PR c++/88976 +// { dg-do compile } + +template void +foo (T x) +{ +#pragma omp parallel + { + #pragma omp cancel parallel if (x) // { dg-error "no match for" } + } +} + +struct S {}; + +void +bar () +{ + S s; + foo (s); +} diff --git a/gcc/testsuite/g++.dg/gomp/cancel-3.C b/gcc/testsuite/g++.dg/gomp/cancel-3.C new file mode 100644 index 00000000000..87e757b7768 --- /dev/null +++ b/gcc/testsuite/g++.dg/gomp/cancel-3.C @@ -0,0 +1,12 @@ +// { dg-do compile } + +struct S { int s; } s; + +void +foo (void) +{ + #pragma omp parallel + { + #pragma omp cancel parallel if (s) // { dg-error "could not convert 's' from 'S' to 'bool'" } + } +} diff --git a/gcc/testsuite/gcc.dg/gomp/cancel-1.c b/gcc/testsuite/gcc.dg/gomp/cancel-1.c new file mode 100644 index 00000000000..c2832905d18 --- /dev/null +++ b/gcc/testsuite/gcc.dg/gomp/cancel-1.c @@ -0,0 +1,12 @@ +/* { dg-do compile } */ + +struct S { int s; } s; + +void +foo (void) +{ + #pragma omp parallel + { + #pragma omp cancel parallel if (s) /* { dg-error "used struct type value where scalar is required" } */ + } +}