Patchwork [gomp4] C++ OpenMP user defined reductions (take 2)

login
register
mail settings
Submitter Jakub Jelinek
Date Sept. 12, 2013, 10:09 a.m.
Message ID <20130912100956.GU1817@tucnak.redhat.com>
Download mbox | patch
Permalink /patch/274489/
State New
Headers show

Comments

Jakub Jelinek - Sept. 12, 2013, 10:09 a.m.
On Thu, Sep 12, 2013 at 10:55:44AM +0200, Jakub Jelinek wrote:
> What is still missing is accessibility checking, in the attached udr5.C
> I'd assume we should error on the dg-error marked lines (because one of the
> UDRs is protected and another one is private).  Not sure what I'm doing
> wrong that it doesn't complain.

I've added (incremental diff) and it works now.


	Jakub

Patch

--- gcc/cp/semantics.c.jj	2013-09-12 11:52:55.886072084 +0200
+++ gcc/cp/semantics.c	2013-09-12 11:52:55.886072084 +0200
@@ -4624,6 +4624,7 @@  omp_reduction_lookup (location_t loc, tre
 						  TREE_OPERAND (id, 1),
 						  type),
 				false, false);
+  tree fns = id;
   if (id && is_overloaded_fn (id))
     id = get_fns (id);
   for (; id; id = OVL_NEXT (id))
@@ -4647,6 +4648,9 @@  omp_reduction_lookup (location_t loc, tre
 	    return id;
 	}
     }
+  if (id && BASELINK_P (fns))
+    perform_or_defer_access_check (BASELINK_BINFO (fns), id, id,
+				   tf_warning_or_error);
   return id;
 }
 
--- gcc/testsuite/g++.dg/gomp/udr-5.C.jj	2013-09-12 11:54:59.873423041 +0200
+++ gcc/testsuite/g++.dg/gomp/udr-5.C	2013-09-12 11:54:43.000000000 +0200
@@ -0,0 +1,41 @@ 
+// { dg-do compile }
+
+struct S
+{
+  int s;
+  S () : s (0) {}
+private:
+  #pragma omp declare reduction (+:S:omp_out.s += omp_in.s)	// { dg-error "is private" }
+protected:
+  #pragma omp declare reduction (-:S:omp_out.s += omp_in.s)	// { dg-error "is protected" }
+};
+
+struct T : public S
+{
+  void foo ()
+  {
+    S s;
+    #pragma omp parallel reduction (S::operator +:s)	// { dg-error "within this context" }
+    s.s = 1;
+    S t;
+    #pragma omp parallel reduction (S::operator -:t)
+    t.s = 1;
+    S u;
+    #pragma omp parallel reduction (+:u)		// { dg-error "within this context" }
+    u.s = 1;
+    S v;
+    #pragma omp parallel reduction (-:v)
+    v.s = 1;
+  }
+};
+
+void
+foo ()
+{
+  S s;
+  #pragma omp parallel reduction (S::operator +:s)	// { dg-error "within this context" }
+  s.s = 1;
+  S t;
+  #pragma omp parallel reduction (S::operator -:t)	// { dg-error "within this context" }
+  t.s = 1;
+}