]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR c++/81154 (OpenMP with shared variable in a template class crash)
authorJakub Jelinek <jakub@redhat.com>
Sat, 16 Sep 2017 18:31:58 +0000 (20:31 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Sat, 16 Sep 2017 18:31:58 +0000 (20:31 +0200)
Backported from mainline
2017-06-21  Jakub Jelinek  <jakub@redhat.com>

PR c++/81154
* semantics.c (handle_omp_array_sections_1, finish_omp_clauses):
Complain about t not being a variable if t is OVERLOAD even
when processing_template_decl.

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

From-SVN: r252878

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

index 4db627a131d4c24ecbed9efb6398e9590a47ebb0..c3d0f47c840e48a18efd3412d4e0621cb668f1fa 100644 (file)
@@ -1,3 +1,13 @@
+2017-09-16  Jakub Jelinek  <jakub@redhat.com>
+
+       Backported from mainline
+       2017-06-21  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/81154
+       * semantics.c (handle_omp_array_sections_1, finish_omp_clauses):
+       Complain about t not being a variable if t is OVERLOAD even
+       when processing_template_decl.
+
 2017-06-08  Jakub Jelinek  <jakub@redhat.com>
 
        PR c/81006
index a2d07aa2722aa607276720586749c9b345c7f182..eb79696a5a8d3f4121aa0e6e566e0e1653f8e0fb 100644 (file)
@@ -4297,7 +4297,7 @@ handle_omp_array_sections_1 (tree c, tree t, vec<tree> &types,
        return error_mark_node;
       if (TREE_CODE (t) != VAR_DECL && TREE_CODE (t) != PARM_DECL)
        {
-         if (processing_template_decl)
+         if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
            return NULL_TREE;
          if (DECL_P (t))
            error_at (OMP_CLAUSE_LOCATION (c),
@@ -5392,7 +5392,7 @@ finish_omp_clauses (tree clauses)
          t = OMP_CLAUSE_DECL (c);
          if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
            {
-             if (processing_template_decl)
+             if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
                break;
              if (DECL_P (t))
                error ("%qD is not a variable in clause %qs", t,
@@ -5417,7 +5417,7 @@ finish_omp_clauses (tree clauses)
          t = OMP_CLAUSE_DECL (c);
          if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
            {
-             if (processing_template_decl)
+             if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
                break;
              if (DECL_P (t))
                error ("%qD is not a variable in clause %<firstprivate%>", t);
@@ -5439,7 +5439,7 @@ finish_omp_clauses (tree clauses)
          t = OMP_CLAUSE_DECL (c);
          if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
            {
-             if (processing_template_decl)
+             if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
                break;
              if (DECL_P (t))
                error ("%qD is not a variable in clause %<lastprivate%>", t);
@@ -5683,7 +5683,7 @@ finish_omp_clauses (tree clauses)
          t = OMP_CLAUSE_DECL (c);
          if (TREE_CODE (t) != VAR_DECL && TREE_CODE (t) != PARM_DECL)
            {
-             if (processing_template_decl)
+             if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
                break;
              if (DECL_P (t))
                error ("%qD is not a variable in %<aligned%> clause", t);
@@ -5753,7 +5753,7 @@ finish_omp_clauses (tree clauses)
            remove = true;
          else if (TREE_CODE (t) != VAR_DECL && TREE_CODE (t) != PARM_DECL)
            {
-             if (processing_template_decl)
+             if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
                break;
              if (DECL_P (t))
                error ("%qD is not a variable in %<depend%> clause", t);
@@ -5795,7 +5795,7 @@ finish_omp_clauses (tree clauses)
            remove = true;
          else if (TREE_CODE (t) != VAR_DECL && TREE_CODE (t) != PARM_DECL)
            {
-             if (processing_template_decl)
+             if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
                break;
              if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
                  && OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_POINTER)
index 7c6425f679c8db9a255834022f5ef3967c500d9a..02db110fe5e40cb3f19880621aeaa8fb11c60c77 100644 (file)
@@ -1,3 +1,11 @@
+2017-09-16  Jakub Jelinek  <jakub@redhat.com>
+
+       Backported from mainline
+       2017-06-21  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/81154
+       * g++.dg/gomp/pr81154.C: New test.
+
 2017-09-15  Martin Liska  <mliska@suse.cz>
 
        Backport from mainline
diff --git a/gcc/testsuite/g++.dg/gomp/pr81154.C b/gcc/testsuite/g++.dg/gomp/pr81154.C
new file mode 100644 (file)
index 0000000..f6617dc
--- /dev/null
@@ -0,0 +1,51 @@
+// PR c++/81154
+// { dg-do compile }
+
+template <typename T>
+struct C
+{
+  int foo (T n) const
+  {
+#pragma omp parallel shared (foo)      // { dg-error "is not a variable in clause" }
+    ;
+#pragma omp parallel private (foo)     // { dg-error "is not a variable in clause" }
+    ;
+#pragma omp parallel firstprivate (foo)        // { dg-error "is not a variable in clause" }
+    ;
+#pragma omp parallel for lastprivate (foo)     // { dg-error "is not a variable in clause" }
+    for (T i = 0; i < n; i++)
+      ;
+#pragma omp parallel reduction (+:foo) // { dg-error "is not a variable in clause" }
+    ;
+    return 0;
+  }
+  int foo (int x, int y) { return x; }
+};
+
+struct D
+{
+  typedef int T;
+  int foo (T n) const
+  {
+#pragma omp parallel shared (foo)      // { dg-error "is not a variable in clause" }
+    ;
+#pragma omp parallel private (foo)     // { dg-error "is not a variable in clause" }
+    ;
+#pragma omp parallel firstprivate (foo)        // { dg-error "is not a variable in clause" }
+    ;
+#pragma omp parallel for lastprivate (foo)     // { dg-error "is not a variable in clause" }
+    for (T i = 0; i < n; i++)
+      ;
+#pragma omp parallel reduction (+:foo) // { dg-error "is not a variable in clause" }
+    ;
+    return 0;
+  }
+  int foo (int x, int y) { return x; }
+};
+
+int
+main ()
+{
+  C<int> ().foo (1);
+  D ().foo (1);
+}