[patch, fortran] Fix PR 100227, write with implied DO loop

2021-07-04 Thread Thomas Koenig via Fortran

Hello world,

after a bit of an absence, I am now back, at least for some regression
fixing (and for reviewing patches, if that is called for).

So, here's a regression fix to start with.

OK for trunk and affected branches (down to 9)?

Best regards

Thomas

Do not replace variable op variable in I/O implied DO loop replacement.

This PR came about because index expressions of the form k+k in
implied DO loops in I/O statements were considered for replacement
by array slices.

Fixed by only doing the transformation if the expression is of the
type expr OP contastant.

gcc/fortran/ChangeLog:

PR fortran/100227
* frontend-passes.c (traverse_io_block): Adjust test for
when a variable is eligible for the transformation to
array slice.

gcc/testsuite/ChangeLog:

PR fortran/100227
* gfortran.dg/implied_do_io_7.f90: New test.
diff --git a/gcc/fortran/frontend-passes.c b/gcc/fortran/frontend-passes.c
index 72a4e0410b1..996dcc2e547 100644
--- a/gcc/fortran/frontend-passes.c
+++ b/gcc/fortran/frontend-passes.c
@@ -1299,8 +1299,8 @@ traverse_io_block (gfc_code *code, bool *has_reached, gfc_code *prev)
 		std::swap (start->value.op.op1, start->value.op.op2);
 	  gcc_fallthrough ();
 	case INTRINSIC_MINUS:
-	  if ((start->value.op.op1->expr_type!= EXPR_VARIABLE
-		   && start->value.op.op2->expr_type != EXPR_CONSTANT)
+	  if (start->value.op.op1->expr_type!= EXPR_VARIABLE
+		  || start->value.op.op2->expr_type != EXPR_CONSTANT
 		  || start->value.op.op1->ref)
 		return false;
 	  if (!stack_top || !stack_top->iter
diff --git a/gcc/testsuite/gfortran.dg/implied_do_io_7.f90 b/gcc/testsuite/gfortran.dg/implied_do_io_7.f90
new file mode 100644
index 000..63927aafea9
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/implied_do_io_7.f90
@@ -0,0 +1,16 @@
+! { dg-do run }
+! PR 100227 - this was falsely optimized, leading to nonsense  results.
+! Original test case by "Mathieu".
+
+program p
+  implicit none
+  integer, parameter :: nbmode = 3
+  integer :: k
+  real:: mass(nbmode*2)
+  character (len=80) :: line
+  do k = 1, nbmode*2
+ mass(k) = k
+  end do
+  write (unit=line,fmt='(*(F6.2))') (mass(k+k), k=1,nbmode)
+  if (line /= '  2.00  4.00  6.00') stop 1
+end program


Installation in MAC M1

2021-07-04 Thread Soumyadip Sahoo via Fortran
HII, I am soumyadip ,from India , I want to install fortran compiler in my Mac 
Pro M1 processor . Please give me proper way to installation , it will be very 
helpful. 
Thank you,

Re: Installation in MAC M1

2021-07-04 Thread Iain Sandoe via Fortran
Hello Soumyadip,

> On 5 Jul 2021, at 07:18, Soumyadip Sahoo via Fortran  
> wrote:
> 
> HII, I am soumyadip ,from India , I want to install fortran compiler in my 
> Mac Pro M1 processor . Please give me proper way to installation , it will be 
> very helpful. 

GCC (and therefore gfortran) support is experimental on M1, while you could 
build from source, probably the easiest way is to use homebrew (see the 
homebrew website for information).

thanks
Iain