Dear All,

This was a slip up on my part.  The fix is obvious - OK for trunk and 4.9?

Cheers

Paul

2014-06-09  Paul Thomas  <pa...@gcc.gnu.org>

    PR fortran/61406
    * trans-stmt.c (trans_associate_var): Check that array
    constructors are constant for direct reference.

2014-06-09  Paul Thomas  <pa...@gcc.gnu.org>

    PR fortran/61406
    * gfortran.dg/associate_17.f90 : New test
Index: gcc/fortran/trans-stmt.c
===================================================================
*** gcc/fortran/trans-stmt.c    (revision 211365)
--- gcc/fortran/trans-stmt.c    (working copy)
*************** trans_associate_var (gfc_symbol *sym, gf
*** 1167,1179 ****
      {
        gfc_se se;
        tree desc;
  
        desc = sym->backend_decl;
  
        /* If association is to an expression, evaluate it and create temporary.
         Otherwise, get descriptor of target for pointer assignment.  */
        gfc_init_se (&se, NULL);
!       if (sym->assoc->variable || e->expr_type == EXPR_ARRAY)
        {
          se.direct_byref = 1;
          se.use_offset = 1;
--- 1167,1182 ----
      {
        gfc_se se;
        tree desc;
+       bool cst_array_ctor;
  
        desc = sym->backend_decl;
+       cst_array_ctor = e->expr_type == EXPR_ARRAY
+             && gfc_constant_array_constructor_p (e->value.constructor);
  
        /* If association is to an expression, evaluate it and create temporary.
         Otherwise, get descriptor of target for pointer assignment.  */
        gfc_init_se (&se, NULL);
!       if (sym->assoc->variable || cst_array_ctor)
        {
          se.direct_byref = 1;
          se.use_offset = 1;
*************** trans_associate_var (gfc_symbol *sym, gf
*** 1184,1190 ****
  
        /* If we didn't already do the pointer assignment, set associate-name
         descriptor to the one generated for the temporary.  */
!       if (!sym->assoc->variable && e->expr_type != EXPR_ARRAY)
        {
          int dim;
  
--- 1187,1193 ----
  
        /* If we didn't already do the pointer assignment, set associate-name
         descriptor to the one generated for the temporary.  */
!       if (!sym->assoc->variable && !cst_array_ctor)
        {
          int dim;
  
Index: gcc/testsuite/gfortran.dg/associate_17.f90
===================================================================
*** gcc/testsuite/gfortran.dg/associate_17.f90  (revision 0)
--- gcc/testsuite/gfortran.dg/associate_17.f90  (working copy)
***************
*** 0 ****
--- 1,12 ----
+ ! { dg-do run }
+ ! Test the fix for PR61406
+ ! Contributed by Adam Hirst  <a...@aphirst.karoo.co.uk>
+ program test
+   implicit none
+   real :: theta = 1.0
+ 
+   associate (n => [cos(theta), sin(theta)])
+     if (abs (norm2(n) - 1.0) .gt. 1.0e-4) call abort
+   end associate
+ 
+ end program test

Reply via email to