Hi!

If the typeinfo decls appear in OpenMP default(none) regions, as we no longer
predetermine const with no mutable members, they are diagnosed as errors,
but it isn't something the users can actually provide explicit sharing for in
the clauses.

This patch makes those predetermined shared.
Bootstrapped/regtested on x86_64-linux and i686-linux, committed to trunk.

2020-01-29  Jakub Jelinek  <ja...@redhat.com>

        PR c++/91118
        * cp-gimplify.c (cxx_omp_predetermined_sharing): Return
        OMP_CLAUSE_DEFAULT_SHARED for typeinfo decls.

        * g++.dg/gomp/pr91118-1.C: New test.
        * g++.dg/gomp/pr91118-2.C: New test.

--- gcc/cp/cp-gimplify.c.jj     2020-01-15 00:26:26.563527365 +0100
+++ gcc/cp/cp-gimplify.c        2020-01-28 13:24:11.821423237 +0100
@@ -2187,6 +2187,10 @@ cxx_omp_predetermined_sharing (tree decl
           && DECL_OMP_PRIVATIZED_MEMBER (decl)))
     return OMP_CLAUSE_DEFAULT_SHARED;
 
+  /* Similarly for typeinfo symbols.  */
+  if (VAR_P (decl) && DECL_ARTIFICIAL (decl) && DECL_TINFO_P (decl))
+    return OMP_CLAUSE_DEFAULT_SHARED;
+
   return OMP_CLAUSE_DEFAULT_UNSPECIFIED;
 }
 
--- gcc/testsuite/g++.dg/gomp/pr91118-1.C.jj    2020-01-28 13:38:22.450743210 
+0100
+++ gcc/testsuite/g++.dg/gomp/pr91118-1.C       2020-01-28 13:41:00.557385504 
+0100
@@ -0,0 +1,12 @@
+// PR c++/91118
+// { dg-do compile }
+// { dg-additional-options "-fsanitize=undefined" }
+
+#include <iostream>
+
+void
+foo ()
+{
+#pragma omp parallel default(none) shared(std::cerr)
+  std::cerr << "hello" << std::endl;
+}
--- gcc/testsuite/g++.dg/gomp/pr91118-2.C.jj    2020-01-28 13:39:29.055749988 
+0100
+++ gcc/testsuite/g++.dg/gomp/pr91118-2.C       2020-01-28 13:39:46.446490655 
+0100
@@ -0,0 +1,14 @@
+// PR c++/91118
+// { dg-do compile }
+
+#include <typeinfo>
+
+struct S { virtual ~S (); };
+void bar (const std::type_info &, const std::type_info &);
+
+void
+foo (S *p)
+{
+  #pragma omp parallel default (none) firstprivate (p)
+    bar (typeid (*p), typeid (S));
+}

        Jakub

Reply via email to