]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
openmp: Add testcase for threadprivate random access class iterators
authorTobias Burnus <tobias@codesourcery.com>
Tue, 2 Nov 2021 14:51:22 +0000 (15:51 +0100)
committerTobias Burnus <tobias@codesourcery.com>
Tue, 2 Nov 2021 14:51:22 +0000 (15:51 +0100)
This adds a testcase for random access class iterators.  The diagnostics
can be different between templates and non-templates, as for some
threadprivate vars finish_id_expression replaces them with call to their
corresponding wrapper, but I think it is not that big deal, we reject
it in either case.

2021-11-02  Jakub Jelinek  <jakub@redhat.com>

* g++.dg/gomp/loop-8.C: New test.

(cherry picked from commit fb7fee84813b23487baf0c1094860251229ab5dd)

gcc/testsuite/ChangeLog.omp
gcc/testsuite/g++.dg/gomp/loop-8.C [new file with mode: 0644]

index 58304e7c1fa7386914952b7215a335b6969cfb60..f0036d95396c7da43ef654efd8ba396219377bba 100644 (file)
@@ -1,3 +1,10 @@
+2021-11-02  Tobias Burnus  <tobias@codesourcery.com>
+
+       Backport from master:
+       2021-11-02  Jakub Jelinek  <jakub@redhat.com>
+       
+       * g++.dg/gomp/loop-8.C: New test.
+
 2021-11-02  Tobias Burnus  <tobias@codesourcery.com>
 
        Backport from master:
diff --git a/gcc/testsuite/g++.dg/gomp/loop-8.C b/gcc/testsuite/g++.dg/gomp/loop-8.C
new file mode 100644 (file)
index 0000000..41a1817
--- /dev/null
@@ -0,0 +1,128 @@
+typedef __PTRDIFF_TYPE__ ptrdiff_t;
+
+template <typename T>
+class I
+{
+public:
+  typedef ptrdiff_t difference_type;
+  I ();
+  ~I ();
+  I (T *);
+  I (const I &);
+  T &operator * ();
+  T *operator -> ();
+  T &operator [] (const difference_type &) const;
+  I &operator = (const I &);
+  I &operator ++ ();
+  I operator ++ (int);
+  I &operator -- ();
+  I operator -- (int);
+  I &operator += (const difference_type &);
+  I &operator -= (const difference_type &);
+  I operator + (const difference_type &) const;
+  I operator - (const difference_type &) const;
+  template <typename S> friend bool operator == (I<S> &, I<S> &);
+  template <typename S> friend bool operator == (const I<S> &, const I<S> &);
+  template <typename S> friend bool operator < (I<S> &, I<S> &);
+  template <typename S> friend bool operator < (const I<S> &, const I<S> &);
+  template <typename S> friend bool operator <= (I<S> &, I<S> &);
+  template <typename S> friend bool operator <= (const I<S> &, const I<S> &);
+  template <typename S> friend bool operator > (I<S> &, I<S> &);
+  template <typename S> friend bool operator > (const I<S> &, const I<S> &);
+  template <typename S> friend bool operator >= (I<S> &, I<S> &);
+  template <typename S> friend bool operator >= (const I<S> &, const I<S> &);
+  template <typename S> friend typename I<S>::difference_type operator - (I<S> &, I<S> &);
+  template <typename S> friend typename I<S>::difference_type operator - (const I<S> &, const I<S> &);
+  template <typename S> friend I<S> operator + (typename I<S>::difference_type , const I<S> &);
+private:
+  T *p;
+};
+
+template <typename T> bool operator == (I<T> &, I<T> &);
+template <typename T> bool operator == (const I<T> &, const I<T> &);
+template <typename T> bool operator != (I<T> &, I<T> &);
+template <typename T> bool operator != (const I<T> &, const I<T> &);
+template <typename T> bool operator < (I<T> &, I<T> &);
+template <typename T> bool operator < (const I<T> &, const I<T> &);
+template <typename T> bool operator <= (I<T> &, I<T> &);
+template <typename T> bool operator <= (const I<T> &, const I<T> &);
+template <typename T> bool operator > (I<T> &, I<T> &);
+template <typename T> bool operator > (const I<T> &, const I<T> &);
+template <typename T> bool operator >= (I<T> &, I<T> &);
+template <typename T> bool operator >= (const I<T> &, const I<T> &);
+template <typename T> typename I<T>::difference_type operator - (I<T> &, I<T> &);
+template <typename T> typename I<T>::difference_type operator - (const I<T> &, const I<T> &);
+template <typename T> I<T> operator + (typename I<T>::difference_type, const I<T> &);
+
+extern I<int> i, j;
+#pragma omp threadprivate (i, j)
+extern I<int> k, l;
+#pragma omp threadprivate (k, l)
+I<int> k, l;
+
+void
+f1 (I<int> &x, I<int> &y)
+{
+  #pragma omp for collapse(2)
+  for (i = x; i < y; i++)      // { dg-error "expected iteration declaration or initialization" }
+    for (j = x; j < y; j++)
+      ;
+}
+
+void
+f2 (I<int> &x, I<int> &y)
+{
+  #pragma omp for collapse(2)
+  for (k = x; k < y; k++)      // { dg-error "expected iteration declaration or initialization" }
+    for (l = x; l < y; l++)
+      ;
+}
+
+template <int N>
+void
+f3 (I<int> &x, I<int> &y)
+{
+  #pragma omp for collapse(2)
+  for (i = x; i < y; i++)      // { dg-error "'i' is predetermined 'threadprivate' for 'private'" }
+    for (j = x; j < y; j++)    // { dg-error "'j' is predetermined 'threadprivate' for 'private'" }
+      ;
+}
+
+template <int N>
+void
+f4 (I<int> &x, I<int> &y)
+{
+  #pragma omp for collapse(2)
+  for (k = x; k < y; k++)      // { dg-error "'k' is predetermined 'threadprivate' for 'private'" }
+    for (l = x; l < y; l++)    // { dg-error "'l' is predetermined 'threadprivate' for 'private'" }
+      ;
+}
+
+template <typename T>
+void
+f5 (I<T> &x, I<T> &y)
+{
+  #pragma omp for collapse(2)  // { dg-error "expected iteration declaration or initialization" }
+  for (i = x; i < y; i++)      // { dg-error "'i' is predetermined 'threadprivate' for 'private'" }
+    for (j = x; j < y; j++)    // { dg-error "'j' is predetermined 'threadprivate' for 'private'" }
+      ;
+}
+
+template <typename T>
+void
+f6 (I<T> &x, I<T> &y)
+{
+  #pragma omp for collapse(2)  // { dg-error "expected iteration declaration or initialization" }
+  for (k = x; k < y; k++)      // { dg-error "'k' is predetermined 'threadprivate' for 'private'" }
+    for (l = x; l < y; l++)    // { dg-error "'l' is predetermined 'threadprivate' for 'private'" }
+      ;
+}
+
+void
+test (I<int> &x, I<int> &y)
+{
+  f3<0> (x, y);
+  f4<0> (x, y);
+  f5 (x, y);
+  f6 (x, y);
+}