This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[gomp] Pass TREE_ADDRESSABLE by reference to children threads
- From: Diego Novillo <dnovillo at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Tue, 18 Oct 2005 18:50:03 -0400
- Subject: [gomp] Pass TREE_ADDRESSABLE by reference to children threads
As discussed earlier. This fixes:
p = &x;
#pragma omp parallel
{
if (p != &x)
abort ();
}
where both 'p' and 'x' are implicitly shared. By passing 'x' by reference,
we avoid comparing 'p' against the address of a field in .omp_data_s.
2005-10-18 Diego Novillo <dnovillo@redhat.com>
* omp-low.c (use_pointer_for_field): Return true for
TREE_ADDRESSABLE decls.
libgomp/
* testsuite/libgomp.dg/shared-3.c: New test.
Index: gcc/omp-low.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/omp-low.c,v
retrieving revision 1.1.2.25
diff -d -u -p -r1.1.2.25 omp-low.c
--- gcc/omp-low.c 18 Oct 2005 19:06:57 -0000 1.1.2.25
+++ gcc/omp-low.c 18 Oct 2005 22:43:11 -0000
@@ -61,7 +61,7 @@ Software Foundation, 51 Franklin Street,
typedef struct omp_context
{
- /* This field must be at the beginning, as we do "inheritence". */
+ /* This field must be at the beginning, as we do "inheritance". */
copy_body_data cb;
/* The tree of contexts corresponding to the encountered constructs. */
@@ -166,7 +166,8 @@ maybe_lookup_field (tree var, omp_contex
return n ? (tree) n->value : NULL_TREE;
}
-/* Return true if DECL should be copied by pointer. */
+/* Return true if DECL should be copied by pointer. SHARED_P is true
+ if DECL is to be shared. */
static bool
use_pointer_for_field (tree decl, bool shared_p)
@@ -174,6 +175,11 @@ use_pointer_for_field (tree decl, bool s
if (AGGREGATE_TYPE_P (TREE_TYPE (decl)))
return true;
+ /* Do not use copy-in/copy-out for variables that have their address
+ taken. */
+ if (TREE_ADDRESSABLE (decl))
+ return true;
+
/* We can only use copy-in/copy-out semantics for shared varibles
when we know the value is not accessible from an outer scope. */
if (shared_p)
Index: libgomp/testsuite/libgomp.dg/shared-3.c
===================================================================
RCS file: libgomp/testsuite/libgomp.dg/shared-3.c
diff -N libgomp/testsuite/libgomp.dg/shared-3.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ libgomp/testsuite/libgomp.dg/shared-3.c 18 Oct 2005 22:43:15 -0000
@@ -0,0 +1,19 @@
+/* { dg-do run } */
+
+void abort (void);
+
+int main()
+{
+ int x;
+ int *p;
+
+ p = &x;
+
+ #pragma omp parallel
+ {
+ if (p != &x)
+ abort ();
+ }
+
+ return 0;
+}