]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR c++/79664 (ICE with #pragma omp parallel in constexpr function)
authorJakub Jelinek <jakub@redhat.com>
Tue, 30 May 2017 08:04:55 +0000 (10:04 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 30 May 2017 08:04:55 +0000 (10:04 +0200)
Backported from mainline
2017-02-22  Jakub Jelinek  <jakub@redhat.com>

PR c++/79664
* parser.c (cp_parser_omp_teams, cp_parser_omp_target): Use
SET_EXPR_LOCATION on OMP_TARGET/OMP_TEAMS tree.
* constexpr.c (potential_constant_expression_1): Handle
OMP_*, OACC_* and CILK_* trees.

* g++.dg/gomp/pr79664.C: New test.

From-SVN: r248650

gcc/cp/ChangeLog
gcc/cp/constexpr.c
gcc/cp/parser.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/gomp/pr79664.C [new file with mode: 0644]

index 28bf37995023f82334fe695b167257cb4e5af8b0..9775a4a0aed90c168e7de220bec7cf47880d652c 100644 (file)
@@ -1,6 +1,14 @@
 2017-05-30  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
+       2017-02-22  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/79664
+       * parser.c (cp_parser_omp_teams, cp_parser_omp_target): Use
+       SET_EXPR_LOCATION on OMP_TARGET/OMP_TEAMS tree.
+       * constexpr.c (potential_constant_expression_1): Handle
+       OMP_*, OACC_* and CILK_* trees.
+
        2017-02-16  Jakub Jelinek  <jakub@redhat.com>
 
        PR c++/79512
index f7a2b9b011787463ea39e33e95b33c0d4c6326e1..b996e98027fb531bb638f98bc576af49159883ca 100644 (file)
@@ -4555,10 +4555,37 @@ potential_constant_expression_1 (tree t, bool want_rval, bool strict,
     case DELETE_EXPR:
     case VEC_DELETE_EXPR:
     case THROW_EXPR:
+    case OMP_PARALLEL:
+    case OMP_TASK:
+    case OMP_FOR:
+    case OMP_DISTRIBUTE:
+    case OMP_TEAMS:
+    case OMP_TARGET_DATA:
+    case OMP_TARGET:
+    case OMP_SECTIONS:
+    case OMP_ORDERED:
+    case OMP_CRITICAL:
+    case OMP_SINGLE:
+    case OMP_SECTION:
+    case OMP_MASTER:
+    case OMP_TASKGROUP:
+    case OMP_TARGET_UPDATE:
     case OMP_ATOMIC:
     case OMP_ATOMIC_READ:
     case OMP_ATOMIC_CAPTURE_OLD:
     case OMP_ATOMIC_CAPTURE_NEW:
+    case OACC_PARALLEL:
+    case OACC_KERNELS:
+    case OACC_DATA:
+    case OACC_HOST_DATA:
+    case OACC_LOOP:
+    case OACC_CACHE:
+    case OACC_DECLARE:
+    case OACC_ENTER_DATA:
+    case OACC_EXIT_DATA:
+    case OACC_UPDATE:
+    case CILK_SIMD:
+    case CILK_FOR:
       /* GCC internal stuff.  */
     case VA_ARG_EXPR:
     case OBJ_TYPE_REF:
@@ -4566,7 +4593,8 @@ potential_constant_expression_1 (tree t, bool want_rval, bool strict,
     case ASM_EXPR:
     fail:
       if (flags & tf_error)
-        error ("expression %qE is not a constant-expression", t);
+       error_at (EXPR_LOC_OR_LOC (t, input_location),
+                 "expression %qE is not a constant-expression", t);
       return false;
 
     case TYPEID_EXPR:
index 4239fee3a584bfe3dc0cde59453407a38008f0db..76868276a02e039638acc18ed847dd7f190b03ae 100644 (file)
@@ -31400,6 +31400,7 @@ cp_parser_omp_teams (cp_parser *parser, cp_token *pragma_tok,
          OMP_TEAMS_CLAUSES (ret) = clauses;
          OMP_TEAMS_BODY (ret) = body;
          OMP_TEAMS_COMBINED (ret) = 1;
+         SET_EXPR_LOCATION (ret, loc);
          return add_stmt (ret);
        }
     }
@@ -31421,6 +31422,7 @@ cp_parser_omp_teams (cp_parser *parser, cp_token *pragma_tok,
   TREE_TYPE (stmt) = void_type_node;
   OMP_TEAMS_CLAUSES (stmt) = clauses;
   OMP_TEAMS_BODY (stmt) = cp_parser_omp_structured_block (parser);
+  SET_EXPR_LOCATION (stmt, loc);
 
   return add_stmt (stmt);
 }
@@ -31545,6 +31547,7 @@ cp_parser_omp_target (cp_parser *parser, cp_token *pragma_tok,
          TREE_TYPE (stmt) = void_type_node;
          OMP_TARGET_CLAUSES (stmt) = cclauses[C_OMP_CLAUSE_SPLIT_TARGET];
          OMP_TARGET_BODY (stmt) = body;
+         SET_EXPR_LOCATION (stmt, pragma_tok->location);
          add_stmt (stmt);
          return true;
        }
index fc6933e070df8a3428235b259aef0d62c0f73d77..910ffe162e5a7985bad5ff98fb5bb4b7ea09ceae 100644 (file)
@@ -1,6 +1,11 @@
 2017-05-30  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
+       2017-02-22  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/79664
+       * g++.dg/gomp/pr79664.C: New test.
+
        2017-02-21  Jakub Jelinek  <jakub@redhat.com>
 
        PR target/79570
diff --git a/gcc/testsuite/g++.dg/gomp/pr79664.C b/gcc/testsuite/g++.dg/gomp/pr79664.C
new file mode 100644 (file)
index 0000000..f796d38
--- /dev/null
@@ -0,0 +1,142 @@
+// PR c++/79664
+// { dg-do compile }
+// { dg-options "-std=c++14 -fopenmp" }
+
+constexpr int
+f1 ()
+{
+  int i = 0;
+#pragma omp parallel for                       // { dg-error "is not a constant-expression" }
+  for (i = 0; i < 10; ++i)
+    ;
+  return 0;
+}
+
+constexpr int
+f2 ()
+{
+  int i = 0;
+#pragma omp parallel                           // { dg-error "is not a constant-expression" }
+  i = 5;
+  return 0;
+}
+
+constexpr int
+f3 ()
+{
+  int i = 0;
+#pragma omp task                               // { dg-error "is not a constant-expression" }
+  i = 5;
+  return 0;
+}
+
+constexpr int
+f4 ()
+{
+  int i = 0;
+#pragma omp for                                        // { dg-error "is not a constant-expression" }
+  for (i = 0; i < 10; ++i)
+    ;
+  return 0;
+}
+
+constexpr int
+f6 ()
+{
+  int i = 0;
+#pragma omp target teams                       // { dg-error "is not a constant-expression" }
+  i = 5;
+  return 0;
+}
+
+constexpr int
+f7 ()
+{
+  int i = 0;
+#pragma omp target data map(tofrom:i)          // { dg-error "is not a constant-expression" }
+  i = 5;
+  return 0;
+}
+
+constexpr int
+f8 ()
+{
+  int i = 0;
+#pragma omp target                             // { dg-error "is not a constant-expression" }
+  i = 5;
+  return 0;
+}
+
+constexpr int
+f9 ()
+{
+  int i = 0;
+#pragma omp sections                           // { dg-error "is not a constant-expression" }
+  {
+#pragma omp section
+    i = 5;
+  }
+  return 0;
+}
+
+constexpr int
+f10 ()
+{
+  int i = 0;
+#pragma omp ordered                            // { dg-error "is not a constant-expression" }
+  i = 1;
+  return 0;
+}
+
+constexpr int
+f11 ()
+{
+  int i = 0;
+#pragma omp critical                           // { dg-error "is not a constant-expression" }
+  i = 1;
+  return 0;
+}
+
+constexpr int
+f12 ()
+{
+  int i = 0;
+#pragma omp single                             // { dg-error "is not a constant-expression" }
+  i = 1;
+  return 0;
+}
+
+constexpr int
+f13 ()
+{
+  int i = 0;
+#pragma omp master                             // { dg-error "is not a constant-expression" }
+  i = 1;
+  return 0;
+}
+
+constexpr int
+f14 ()
+{
+  int i = 0;
+#pragma omp taskgroup                          // { dg-error "is not a constant-expression" }
+  i = 1;
+  return 0;
+}
+
+constexpr int
+f15 ()
+{
+  int i = 0;
+#pragma omp target update to(i)                        // { dg-error "is not a constant-expression" }
+  i = 1;
+  return 0;
+}
+
+constexpr int
+f16 ()
+{
+  int i = 0;
+#pragma omp target update to(i)                        // { dg-error "is not a constant-expression" }
+  return 0;
+}