public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Patch, Fortran + Testsuite] Fix coarray handling in modules
@ 2015-01-02 11:28 Tobias Burnus
  2015-01-02 13:14 ` FX
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Tobias Burnus @ 2015-01-02 11:28 UTC (permalink / raw)
  To: gcc-patches, gfortran, Alessandro Fanfarillo, Mike Stump

[-- Attachment #1: Type: text/plain, Size: 388 bytes --]

As found by Alessandro: Statically allocated coarrays in declared in the 
specification part of a module didn't work (link-time failure). The 
reason was that the associated coarray token was wrongly mangled and not 
a public tree.

I additionally propagated the dg-compile-aux-modules support to caf.dg 
(currently unused).

That's fixed by the attached patch.
OK for the trunk?

Tobias

[-- Attachment #2: caf.diff --]
[-- Type: text/x-patch, Size: 6689 bytes --]

2015-01-02  Tobias Burnus  <burnus@net-b.de>

	* trans-decl.c (gfc_build_qualified_array): Fix coarray tokens
	for module coarrays with -fcoarray=lib.

2015-01-02  Tobias Burnus  <burnus@net-b.de>

	* gfortran.dg/coarray/caf.exp (dg-compile-aux-modules): Add.
	* gfortran.dg/coarray/codimension_2.f90: New.
	* gfortran.dg/coarray/codimension_2a.f90: New.
	* gfortran.dg/coarray_35.f90: New.
	* gfortran.dg/coarray_35a.f90: New.

diff --git a/gcc/fortran/trans-decl.c b/gcc/fortran/trans-decl.c
index 75b84f1..9ef6bfc 100644
--- a/gcc/fortran/trans-decl.c
+++ b/gcc/fortran/trans-decl.c
@@ -819,10 +819,22 @@ gfc_build_qualified_array (tree decl, gfc_symbol * sym)
       && GFC_TYPE_ARRAY_CAF_TOKEN (type) == NULL_TREE)
     {
       tree token;
+      tree token_type = build_qualified_type (pvoid_type_node,
+					      TYPE_QUAL_RESTRICT);
+
+      if (sym->module && (sym->attr.use_assoc
+			  || sym->ns->proc_name->attr.flavor == FL_MODULE))
+	{
+	  tree token_name
+		= get_identifier (gfc_get_string (GFC_PREFIX ("caf_token%s"),
+			IDENTIFIER_POINTER (gfc_sym_mangled_identifier (sym))));
+	  token = build_decl (DECL_SOURCE_LOCATION (decl), VAR_DECL, token_name,
+			      token_type);
+	  TREE_PUBLIC (token) = 1;
+	}
+      else
+	token = gfc_create_var_np (token_type, "caf_token");
 
-      token = gfc_create_var_np (build_qualified_type (pvoid_type_node,
-						       TYPE_QUAL_RESTRICT),
-				 "caf_token");
       GFC_TYPE_ARRAY_CAF_TOKEN (type) = token;
       DECL_ARTIFICIAL (token) = 1;
       TREE_STATIC (token) = 1;
diff --git a/gcc/testsuite/gfortran.dg/coarray/caf.exp b/gcc/testsuite/gfortran.dg/coarray/caf.exp
index 011b5c9..e4e3798 100644
--- a/gcc/testsuite/gfortran.dg/coarray/caf.exp
+++ b/gcc/testsuite/gfortran.dg/coarray/caf.exp
@@ -43,6 +43,21 @@ global DG_TORTURE_OPTIONS torture_with_loops
 torture-init
 set-torture-options $DG_TORTURE_OPTIONS
 
+global gfortran_test_path
+global gfortran_aux_module_flags
+set gfortran_test_path $srcdir/$subdir
+set gfortran_aux_module_flags $DEFAULT_FFLAGS
+proc dg-compile-aux-modules { args } {
+    global gfortran_test_path
+    global gfortran_aux_module_flags
+    if { [llength $args] != 2 } {
+	error "dg-set-target-env-var: needs one argument"
+	return
+    }
+    dg-test $gfortran_test_path/[lindex $args 1] "" $gfortran_aux_module_flags
+    # cleanup-modules isn't intentionally invoked here.
+}
+
 # Main loop.
 foreach test [lsort [glob -nocomplain $srcdir/$subdir/*.\[fF\]{,90,95,03,08} ]] {
     # If we're only testing specific files and this isn't one of them, skip it.
@@ -65,12 +80,14 @@ foreach test [lsort [glob -nocomplain $srcdir/$subdir/*.\[fF\]{,90,95,03,08} ]]
 
     foreach flags $option_list {
 	verbose "Testing $nshort (single), $flags" 1
+        set gfortran_aux_module_flags "-fcoarray=single $flags"
 	dg-test $test "-fcoarray=single $flags" "" 
 	cleanup-modules ""
     }
 
     foreach flags $option_list {
 	verbose "Testing $nshort (libcaf_single), $flags" 1
+        set gfortran_aux_module_flags "-fcoarray=lib $flags -lcaf_single"
 	dg-test $test "-fcoarray=lib $flags -lcaf_single" ""
 	cleanup-modules ""
     }
diff --git a/gcc/testsuite/gfortran.dg/coarray/codimension_2.f90 b/gcc/testsuite/gfortran.dg/coarray/codimension_2.f90
new file mode 100644
index 0000000..b211f9b
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/coarray/codimension_2.f90
@@ -0,0 +1,14 @@
+! { dg-do link }
+! { dg-additional-sources codimension_2a.f90 }
+!
+! To be used with codimension_2a.f90
+! Check that the coarray declared in the module is accessible
+! by doing a link test
+!
+! Contributed by Alessandro Fanfarillo.
+!
+module global_coarrays
+  implicit none
+  integer,parameter :: n=10
+  integer :: b(10)[*]
+end module global_coarrays
diff --git a/gcc/testsuite/gfortran.dg/coarray/codimension_2a.f90 b/gcc/testsuite/gfortran.dg/coarray/codimension_2a.f90
new file mode 100644
index 0000000..8eb472c
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/coarray/codimension_2a.f90
@@ -0,0 +1,26 @@
+! { dg-do compile { target { ! *-*-* } } }
+! SKIP THIS FILE
+!
+! Used by codimension_2.f90
+!
+! Check that the coarray declared in the module is accessible
+! by doing a link test
+!
+! Contributed by Alessandro Fanfarillo.
+!
+program testmod
+  use global_coarrays
+  implicit none
+  
+  integer :: me
+
+  me = this_image()
+
+  b = me
+
+  if(me==1) then
+     b(:) = b(:)[2]
+     write(*,*) b
+  end if
+
+end program testmod
diff --git a/gcc/testsuite/gfortran.dg/coarray/collectives_4.f90 b/gcc/testsuite/gfortran.dg/coarray/collectives_4.f90
new file mode 100644
index 0000000..6e7be46
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/coarray/collectives_4.f90
@@ -0,0 +1,24 @@
+! { dg-do run }
+!
+! CO_REDUCE
+!
+implicit none (type, external)
+intrinsic :: co_reduce
+integer :: stat
+integer :: i4, i4_2, i
+
+i4 = 21 * this_image()
+i4_2 = 21
+do i = 2, num_images()
+  i4_2 = i4_2 * 21 * i
+end do
+call co_reduce(i4, op_i4, stat=stat)
+if (stat /= 0) call abort()
+if (i4_2 /= i4) call abort()
+
+contains
+  pure integer function op_i4(a,b)
+    integer, value :: a, b
+    op_i4 = a * b
+  end function op_i4
+end
diff --git a/gcc/testsuite/gfortran.dg/coarray_35.f90 b/gcc/testsuite/gfortran.dg/coarray_35.f90
new file mode 100644
index 0000000..e65f8fe
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/coarray_35.f90
@@ -0,0 +1,17 @@
+! { dg-do compile }
+! { dg-options "-fcoarray=lib" }
+!
+! To be used with coarray_35a.f90
+! Check that the coarray declared in the module is accessible
+! by checking the assembler name
+!
+! Contributed by Alessandro Fanfarillo.
+!
+module global_coarrays
+  implicit none
+  integer,parameter :: n=10
+  integer :: b(10)[*]
+end module global_coarrays
+
+! Check for the symbol of the coarray token (w/o system-dependend prefix)
+! { dg-final { scan-assembler "caf_token__global_coarrays_MOD_b" } }
diff --git a/gcc/testsuite/gfortran.dg/coarray_35a.f90 b/gcc/testsuite/gfortran.dg/coarray_35a.f90
new file mode 100644
index 0000000..eeeb289
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/coarray_35a.f90
@@ -0,0 +1,28 @@
+! { dg-do compile }
+! { dg-options "-fcoarray=lib" }
+! { dg-compile-aux-modules "coarray_35.f90" }
+!
+! Check that the coarray declared in the module is accessible
+! by checking the assembler name
+!
+! Contributed by Alessandro Fanfarillo.
+!
+program testmod
+  use global_coarrays
+  implicit none
+  
+  integer :: me
+
+  me = this_image()
+
+  b = me
+
+  if(me==1) then
+     b(:) = b(:)[2]
+     write(*,*) b
+  end if
+
+end program testmod
+
+! Check for the symbol of the coarray token (w/o system-dependend prefix)
+! { dg-final { scan-assembler "caf_token__global_coarrays_MOD_b" } }

^ permalink raw reply	[flat|nested] 10+ messages in thread
* Re: [Patch, Fortran + Testsuite] Fix coarray handling in modules
@ 2015-01-03 10:22 Dominique Dhumieres
  2015-01-03 20:50 ` Tobias Burnus
  0 siblings, 1 reply; 10+ messages in thread
From: Dominique Dhumieres @ 2015-01-03 10:22 UTC (permalink / raw)
  To: fortran; +Cc: gcc-patches, fxcoudert, burnus

Happy New Year to all.

The test gfortran.dg/coarray/codimension_2.f90 fails on x86_64-apple-darwin14 with -m32
(see https://gcc.gnu.org/ml/gcc-testresults/2015-01/msg00185.html). The error is

gfc /opt/gcc/work/gcc/testsuite/gfortran.dg/coarray/codimension_2.f90 /opt/gcc/work/gcc/testsuite/gfortran.dg/coarray/codimension_2a.f90 -fcoarray=lib -O2 -lcaf_single -m32
/var/folders/8q/sh_swgz96r7f5vnn08f7fxr00000gn/T//ccPcznrm.s:18:non-relocatable subtraction expression, "__F.caf_token__global_coarrays_MOD_b" minus "L1$pb"
/var/folders/8q/sh_swgz96r7f5vnn08f7fxr00000gn/T//ccPcznrm.s:18:symbol: "__F.caf_token__global_coarrays_MOD_b" can't be undefined in a subtraction expression

Dominique

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2019-03-21 19:27 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-02 11:28 [Patch, Fortran + Testsuite] Fix coarray handling in modules Tobias Burnus
2015-01-02 13:14 ` FX
2015-01-02 20:47 ` Mike Stump
2019-02-28 17:19 ` Thomas Schwinge
2019-03-21 19:34   ` Thomas Schwinge
2015-01-03 10:22 Dominique Dhumieres
2015-01-03 20:50 ` Tobias Burnus
2015-01-03 21:48   ` Dominique d'Humières
2015-01-03 22:30     ` Tobias Burnus
2015-01-03 23:04       ` Dominique d'Humières

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).