diff mbox

[gomp4] fix an ICE involving derived-typed subarray

Message ID 7a233edf-43b2-3c7a-a944-82872d28dbdb@codesourcery.com
State New
Headers show

Commit Message

Cesar Philippidis March 31, 2017, 8:27 p.m. UTC
I'll apply this patch to gomp-4_0-branch shortly which fixes an ICE
triggered by using data clauses with derived-type subarray arguments.
Such subarrays can be handled generically.

Cesar
diff mbox

Patch

2017-03-31  Cesar Philippidis  <cesar@codesourcery.com>

	gcc/fortran/
	* trans-openmp.c (gfc_trans_omp_clauses_1): Update handling of
	subarrays with derived types elements.

	libgomp/
	* testsuite/libgomp.oacc-fortran/derived-type-1.f90: New test.


diff --git a/gcc/fortran/trans-openmp.c b/gcc/fortran/trans-openmp.c
index f3e1773..1d4a15b 100644
--- a/gcc/fortran/trans-openmp.c
+++ b/gcc/fortran/trans-openmp.c
@@ -2064,7 +2064,9 @@  gfc_trans_omp_clauses_1 (stmtblock_t *block, gfc_omp_clauses *clauses,
 		  && (n->expr->ref->next == NULL
 		      || (n->expr->ref->next != NULL
 			  && n->expr->ref->next->type == REF_ARRAY
-			  && n->expr->ref->next->u.ar.type == AR_FULL)))
+			  && n->expr->ref->next->u.ar.type == AR_FULL))
+		  && (n->expr->ref->type == REF_ARRAY
+		      && n->expr->ref->u.ar.type != AR_SECTION))
 		{
 		  gfc_ref *ref = n->expr->ref;
 		  gfc_component *c = ref->u.c.component;
diff --git a/libgomp/testsuite/libgomp.oacc-fortran/derived-type-1.f90 b/libgomp/testsuite/libgomp.oacc-fortran/derived-type-1.f90
new file mode 100644
index 0000000..19b25fc
--- /dev/null
+++ b/libgomp/testsuite/libgomp.oacc-fortran/derived-type-1.f90
@@ -0,0 +1,26 @@ 
+! Test derived types with subarrays
+
+  implicit none
+  type dtype
+     integer :: a, b, c
+  end type dtype
+  integer, parameter :: n = 100
+  integer i
+  type (dtype), dimension(n) :: d
+
+  !$acc data copy(d(1:n))
+  !$acc parallel loop
+  do i = 1, n
+     d(i)%a = i
+     d(i)%b = i-1
+     d(i)%c = i+1
+  end do
+  !$acc end data
+
+  do i = 1, n
+     if (d(i)%a /= i) call abort
+     if (d(i)%b /= i-1) call abort
+     if (d(i)%c /= i+1) call abort
+  end do
+end program
+