Re: [patch, fortran] PR117430 gfortran allows type(C_ptr) in I/O list

2025-02-13 Thread Harald Anlauf

Am 12.02.25 um 21:49 schrieb Jerry D:

The attached patch is fairly obvious. The use of notify_std is changed
to a gfc_error. Several test cases had to be adjusted.

Regression tested on x86_64.

OK for trunk?


This is not a review, just some random comments on the testsuite changes
by your patch:

diff --git a/gcc/testsuite/gfortran.dg/c_loc_test_17.f90
b/gcc/testsuite/gfortran.dg/c_loc_test_17.f90
index 4c2a7d657ee..92bfca4363d 100644
--- a/gcc/testsuite/gfortran.dg/c_loc_test_17.f90
+++ b/gcc/testsuite/gfortran.dg/c_loc_test_17.f90
@@ -1,5 +1,4 @@
 ! { dg-do compile }
-! { dg-options "" }
 !
 ! PR fortran/56378
 ! PR fortran/52426
@@ -24,5 +23,5 @@ contains
 end module

 use iso_c_binding
-print *, c_loc([1]) ! { dg-error "Argument X at .1. to C_LOC shall have
either the POINTER or the TARGET attribute" }
+i = c_loc([1]) ! { dg-error "Argument X at .1. to C_LOC shall have
either the POINTER or the TARGET attribute" }
^^^ i is not declared a type(c_ptr)
 end

diff --git a/gcc/testsuite/gfortran.dg/c_ptr_tests_10.f03
b/gcc/testsuite/gfortran.dg/c_ptr_tests_10.f03
index 4ce1c6809e4..834570cb74d 100644
--- a/gcc/testsuite/gfortran.dg/c_ptr_tests_10.f03
+++ b/gcc/testsuite/gfortran.dg/c_ptr_tests_10.f03
@@ -1,5 +1,4 @@
 ! { dg-do run }
-! { dg-options "-std=gnu" }
 ! This test case exists because gfortran had an error in converting the
 ! expressions for the derived types from iso_c_binding in some cases.
 module c_ptr_tests_10
@@ -7,7 +6,7 @@ module c_ptr_tests_10

 contains
   subroutine sub0() bind(c)
-print *, 'c_null_ptr is: ', c_null_ptr
+print *, 'c_null_ptr is: ', transfer (cptr, C_LONG_LONG)
 
This does not do what one naively might think.
transfer (cptr, C_LONG_LONG) == transfer (cptr, 0)

You probably want: transfer (cptr, 0_C_INTPTR_T)

   end subroutine sub0
 end module c_ptr_tests_10


diff --git a/gcc/testsuite/gfortran.dg/c_ptr_tests_9.f03
b/gcc/testsuite/gfortran.dg/c_ptr_tests_9.f03
index 5a32553b8c5..711b9c157d4 100644
--- a/gcc/testsuite/gfortran.dg/c_ptr_tests_9.f03
+++ b/gcc/testsuite/gfortran.dg/c_ptr_tests_9.f03
@@ -16,9 +16,9 @@ contains
 type(myF90Derived), pointer :: my_f90_type_ptr

 my_f90_type%my_c_ptr = c_null_ptr
-print *, 'my_f90_type is: ', my_f90_type%my_c_ptr
+print *, 'my_f90_type is: ', transfer(my_f90_type%my_c_ptr,
C_LONG_LONG)
 my_f90_type_ptr => my_f90_type
-print *, 'my_f90_type_ptr is: ', my_f90_type_ptr%my_c_ptr
+print *, 'my_f90_type_ptr is: ', transfer(my_f90_type_ptr%my_c_ptr,
 C_LONG_LONG)
   end subroutine sub0
 end module c_ptr_tests_9

Likewise.

diff --git a/gcc/testsuite/gfortran.dg/init_flag_17.f90
b/gcc/testsuite/gfortran.dg/init_flag_17.f90
index 401830fccbc..8bb9f7b1ef7 100644
--- a/gcc/testsuite/gfortran.dg/init_flag_17.f90
+++ b/gcc/testsuite/gfortran.dg/init_flag_17.f90
@@ -19,8 +19,8 @@ program init_flag_17

   type(ty) :: t

-  print *, t%ptr
-  print *, t%fptr
+  print *, transfer(t%ptr, c_long_long)
+  print *, transfer(t%fptr, c_long_long)

 end program

Likewise.


diff --git a/gcc/testsuite/gfortran.dg/pr32601_1.f03
b/gcc/testsuite/gfortran.dg/pr32601_1.f03
index a297e1728ec..1a48419112d 100644
--- a/gcc/testsuite/gfortran.dg/pr32601_1.f03
+++ b/gcc/testsuite/gfortran.dg/pr32601_1.f03
@@ -4,9 +4,9 @@
 ! PR fortran/32601
 use, intrinsic :: iso_c_binding, only: c_loc, c_ptr
 implicit none
-
+integer i
 ! This was causing an ICE, but is an error because the argument to C_LOC
 ! needs to be a variable.
-print *, c_loc(4) ! { dg-error "shall have either the POINTER or the
TARGET attribute" }
+i = c_loc(4) ! { dg-error "shall have either the POINTER or the TARGET
attribute" }

 end

Again, i should be declared as type(c_ptr).

Cheers,
Harald


Regards,

Jerry


Author: Jerry DeLisle 
Date:   Tue Feb 11 20:57:50 2025 -0800

     Fortran:  gfortran allows type(C_ptr) in I/O list

     Before this patch, gfortran was accepting invalid use of
     type(c_ptr) in I/O statements. The fix affects several
     existing test cases so no new test case needed.

     Existing tests were modified to pass by either using the
     transfer function to convert to an acceptable value or
     using an assignment to a like type (non-I/O).

     PR fortran/117430

     gcc/fortran/ChangeLog:

     * resolve.cc (resolve_transfer): Issue the error
     with no exceptions allowed.

     gcc/testsuite/ChangeLog:

     * gfortran.dg/c_loc_test_17.f90: Modify to pass.
     * gfortran.dg/c_ptr_tests_10.f03: Likewise.
     * gfortran.dg/c_ptr_tests_16.f90: Likewise.
     * gfortran.dg/c_ptr_tests_9.f03: Likewise.
     * gfortran.dg/init_flag_17.f90: Likewise.
     * gfortran.dg/pr32601_1.f03: Likewise.





Re: [patch, Fortran] Fix PR 118845

2025-02-13 Thread Thomas Koenig

Hi Jerry,


This is OK.


Pushed as r15-7509.  Thanks for the review!

It would be good to get confirmation that the lapack builds 
now.  I use to be set up here to do that, but dont have it at the moment.


It checked the original test case, that passed.  But yes, a Lapack
tester would be nice.

Now on to PR118862 (but not this today :-)

Best regards

Thomas



Re: 7/7 [Fortran, Patch, Coarray, PR107635] Remove deprecated coarray routines

2025-02-13 Thread Jerry D

On 2/10/25 2:25 AM, Andre Vehreschild wrote:

[PATCH 7/7] Fortran: Remove deprecated coarray routines [PR107635]



I have applied all patches. Regression tested OK here.

From patch 5 there was one reject:

patching file gcc/testsuite/gfortran.dg/coarray/send_char_array_1.f90
Hunk #1 FAILED at 39.
1 out of 1 hunk FAILED -- saving rejects to file 
gcc/testsuite/gfortran.dg/coarray/send_char_array_1.f90.rej


I commented earlier about changing the name of rewrite.cc.

I am now going through the whole enchilada for editorial stuff.

Regards,

Jerry


[patch, Fortran] Fix PR 118845

2025-02-13 Thread Thomas Koenig

Hello world,

this was an interesting regression.  It came from my recent
patch, where an assert was triggered because a procedure artificial
dummy argument generated for a global symbol did not have the
information if if was a function or a subroutine.  Fixed by
adding the information in gfc_get_formal_from_actual_arglist.

This information then uncovered some new errors, also in the
testsuite, which needed fixing.  Finally, the error is made to
look a bit nicer, so the user gets a pointer to where the
original interface comes from, like this:

   10 | CALL bar (test2) ! { dg-error "Interface mismatch in dummy 
procedure" }

  |  1
..
   16 | CALL bar (test) ! { dg-error "Interface mismatch in dummy 
procedure" }

  |  2
Fehler: Interface mismatch in dummy procedure at (1) conflichts with 
(2): 'test2' is not a subroutine


Regression-tested. OK for trunk?

Best regards

Thomas

gcc/fortran/ChangeLog:

PR fortran/118845
* interface.cc (compare_parameter): If the formal attribute has been
generated from an actual argument list, also output an pointer to
there in case of an error.
(gfc_get_formal_from_actual_arglist): Set function and subroutine
attributes and (if it is a function) the typespec from the actual
argument.

gcc/testsuite/ChangeLog:

PR fortran/118845
* gfortran.dg/recursive_check_4.f03: Adjust call so types matche.
* gfortran.dg/recursive_check_6.f03: Likewise.
* gfortran.dg/specifics_2.f90: Adjust calls so types match.
* gfortran.dg/interface_52.f90: New test.
* gfortran.dg/interface_53.f90: New test.
diff --git a/gcc/fortran/interface.cc b/gcc/fortran/interface.cc
index fdde84db80d..edec907d33a 100644
--- a/gcc/fortran/interface.cc
+++ b/gcc/fortran/interface.cc
@@ -2474,8 +2474,16 @@ compare_parameter (gfc_symbol *formal, gfc_expr *actual,
 	   sizeof(err),NULL, NULL))
 	{
 	  if (where)
-	gfc_error_opt (0, "Interface mismatch in dummy procedure %qs at %L:"
-			   " %s", formal->name, &actual->where, err);
+	{
+	  /* Artificially generated symbol names would only confuse.  */
+	  if (formal->attr.artificial)
+		gfc_error_opt (0, "Interface mismatch in dummy procedure "
+			   "at %L conflicts with %L: %s", &actual->where,
+			   &formal->declared_at, err);
+	  else
+		gfc_error_opt (0, "Interface mismatch in dummy procedure %qs "
+			   "at %L: %s", formal->name, &actual->where, err);
+	}
 	  return false;
 	}
 
@@ -2483,8 +2491,16 @@ compare_parameter (gfc_symbol *formal, gfc_expr *actual,
    sizeof(err), NULL, NULL))
 	{
 	  if (where)
-	gfc_error_opt (0, "Interface mismatch in dummy procedure %qs at %L:"
-			   " %s", formal->name, &actual->where, err);
+	{
+	  if (formal->attr.artificial)
+		gfc_error_opt (0, "Interface mismatch in dummy procedure "
+			   "at %L conflichts with %L: %s", &actual->where,
+			   &formal->declared_at, err);
+	  else
+		gfc_error_opt (0, "Interface mismatch in dummy procedure %qs at "
+			   "%L: %s", formal->name, &actual->where, err);
+
+	}
 	  return false;
 	}
 
@@ -5822,7 +5838,14 @@ gfc_get_formal_from_actual_arglist (gfc_symbol *sym,
 	  gfc_get_symbol (name, gfc_current_ns, &s);
 	  if (a->expr->ts.type == BT_PROCEDURE)
 	{
+	  gfc_symbol *asym = a->expr->symtree->n.sym;
 	  s->attr.flavor = FL_PROCEDURE;
+	  if (asym->attr.function)
+		{
+		  s->attr.function = 1;
+		  s->ts = asym->ts;
+		}
+	  s->attr.subroutine = asym->attr.subroutine;
 	}
 	  else
 	{
diff --git a/gcc/testsuite/gfortran.dg/interface_52.f90 b/gcc/testsuite/gfortran.dg/interface_52.f90
new file mode 100644
index 000..4d619241c27
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/interface_52.f90
@@ -0,0 +1,20 @@
+  ! { dg-do compile }
+MODULE m
+  IMPLICIT NONE
+
+CONTAINS
+
+  SUBROUTINE test ()
+IMPLICIT NONE
+
+CALL bar (test2) ! { dg-error "Interface mismatch in dummy procedure" }
+  END SUBROUTINE test
+
+  INTEGER FUNCTION test2 () RESULT (x)
+IMPLICIT NONE
+
+CALL bar (test) ! { dg-error "Interface mismatch in dummy procedure" }
+  END FUNCTION test2
+
+END MODULE m
+
diff --git a/gcc/testsuite/gfortran.dg/interface_53.f90 b/gcc/testsuite/gfortran.dg/interface_53.f90
new file mode 100644
index 000..99a2b959463
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/interface_53.f90
@@ -0,0 +1,8 @@
+! { dg-do compile }
+! PR 118845 - reduced from a segfault in Lapack.
+SUBROUTINE SDRVES(  RESULT )
+  external SSLECT
+  CALL SGEES( SSLECT )
+  CALL SGEES( SSLECT )
+  RESULT = SSLECT( 1, 2 )
+END
diff --git a/gcc/testsuite/gfortran.dg/recursive_check_4.f03 b/gcc/testsuite/gfortran.dg/recursive_check_4.f03
index ece42ca2312..da45762f9b1 100644
--- a/gcc/testsuite/gfortran.dg/recursive_check_4.f03
+++ b/gcc/testsuite/gfortran.dg/recursive_check_4.f03
@@ -20,7 +20,7 @@ CONTAINS
 IMPLICIT NONE
 PRO

Re: [patch, Fortran] Fix PR 118845

2025-02-13 Thread Jerry D

On 2/13/25 11:59 AM, Thomas Koenig wrote:

Hello world,

this was an interesting regression.  It came from my recent
patch, where an assert was triggered because a procedure artificial
dummy argument generated for a global symbol did not have the
information if if was a function or a subroutine.  Fixed by
adding the information in gfc_get_formal_from_actual_arglist.

This information then uncovered some new errors, also in the
testsuite, which needed fixing.  Finally, the error is made to
look a bit nicer, so the user gets a pointer to where the
original interface comes from, like this:

    10 | CALL bar (test2) ! { dg-error "Interface mismatch in dummy 
procedure" }

   |  1
..
    16 | CALL bar (test) ! { dg-error "Interface mismatch in dummy 
procedure" }

   |  2
Fehler: Interface mismatch in dummy procedure at (1) conflichts with 
(2): 'test2' is not a subroutine


Regression-tested. OK for trunk?


This is OK. It would be good to get confirmation that the lapack builds 
now.  I use to be set up here to do that, but dont have it at the moment.


Thanks for the quick fix.

Jerry


Best regards

 Thomas

gcc/fortran/ChangeLog:

 PR fortran/118845
 * interface.cc (compare_parameter): If the formal attribute has been
 generated from an actual argument list, also output an pointer to
 there in case of an error.
 (gfc_get_formal_from_actual_arglist): Set function and subroutine
 attributes and (if it is a function) the typespec from the actual
 argument.

gcc/testsuite/ChangeLog:

 PR fortran/118845
 * gfortran.dg/recursive_check_4.f03: Adjust call so types matche.
 * gfortran.dg/recursive_check_6.f03: Likewise.
 * gfortran.dg/specifics_2.f90: Adjust calls so types match.
 * gfortran.dg/interface_52.f90: New test.
 * gfortran.dg/interface_53.f90: New test.




Re: [patch, fortran] PR117430 gfortran allows type(C_ptr) in I/O list

2025-02-13 Thread Jerry D

On 2/13/25 1:42 PM, Harald Anlauf wrote:

Am 12.02.25 um 21:49 schrieb Jerry D:

The attached patch is fairly obvious. The use of notify_std is changed
to a gfc_error. Several test cases had to be adjusted.

Regression tested on x86_64.

OK for trunk?


This is not a review, just some random comments on the testsuite changes
by your patch:



I will update and give the i some declarations. I just tried integer and 
it worked. Of course you are correct to declasre these as type(c_ptr)


Regarding, the use of transfer, I will fix those as well.

The patch itself is trivial so I will wait a day or so for any other 
comments.


Thanks for feedback.

Jerry




diff --git a/gcc/testsuite/gfortran.dg/c_loc_test_17.f90
b/gcc/testsuite/gfortran.dg/c_loc_test_17.f90
index 4c2a7d657ee..92bfca4363d 100644
--- a/gcc/testsuite/gfortran.dg/c_loc_test_17.f90
+++ b/gcc/testsuite/gfortran.dg/c_loc_test_17.f90
@@ -1,5 +1,4 @@
  ! { dg-do compile }
-! { dg-options "" }
  !
  ! PR fortran/56378
  ! PR fortran/52426
@@ -24,5 +23,5 @@ contains
  end module

  use iso_c_binding
-print *, c_loc([1]) ! { dg-error "Argument X at .1. to C_LOC shall have
either the POINTER or the TARGET attribute" }
+i = c_loc([1]) ! { dg-error "Argument X at .1. to C_LOC shall have
either the POINTER or the TARGET attribute" }
^^^ i is not declared a type(c_ptr)
  end

diff --git a/gcc/testsuite/gfortran.dg/c_ptr_tests_10.f03
b/gcc/testsuite/gfortran.dg/c_ptr_tests_10.f03
index 4ce1c6809e4..834570cb74d 100644
--- a/gcc/testsuite/gfortran.dg/c_ptr_tests_10.f03
+++ b/gcc/testsuite/gfortran.dg/c_ptr_tests_10.f03
@@ -1,5 +1,4 @@
  ! { dg-do run }
-! { dg-options "-std=gnu" }
  ! This test case exists because gfortran had an error in converting the
  ! expressions for the derived types from iso_c_binding in some cases.
  module c_ptr_tests_10
@@ -7,7 +6,7 @@ module c_ptr_tests_10

  contains
    subroutine sub0() bind(c)
-    print *, 'c_null_ptr is: ', c_null_ptr
+    print *, 'c_null_ptr is: ', transfer (cptr, C_LONG_LONG)
  
This does not do what one naively might think.
transfer (cptr, C_LONG_LONG) == transfer (cptr, 0)

You probably want: transfer (cptr, 0_C_INTPTR_T)

    end subroutine sub0
  end module c_ptr_tests_10


diff --git a/gcc/testsuite/gfortran.dg/c_ptr_tests_9.f03
b/gcc/testsuite/gfortran.dg/c_ptr_tests_9.f03
index 5a32553b8c5..711b9c157d4 100644
--- a/gcc/testsuite/gfortran.dg/c_ptr_tests_9.f03
+++ b/gcc/testsuite/gfortran.dg/c_ptr_tests_9.f03
@@ -16,9 +16,9 @@ contains
  type(myF90Derived), pointer :: my_f90_type_ptr

  my_f90_type%my_c_ptr = c_null_ptr
-    print *, 'my_f90_type is: ', my_f90_type%my_c_ptr
+    print *, 'my_f90_type is: ', transfer(my_f90_type%my_c_ptr,
C_LONG_LONG)
  my_f90_type_ptr => my_f90_type
-    print *, 'my_f90_type_ptr is: ', my_f90_type_ptr%my_c_ptr
+    print *, 'my_f90_type_ptr is: ', transfer(my_f90_type_ptr%my_c_ptr,
  C_LONG_LONG)
    end subroutine sub0
  end module c_ptr_tests_9

Likewise.

diff --git a/gcc/testsuite/gfortran.dg/init_flag_17.f90
b/gcc/testsuite/gfortran.dg/init_flag_17.f90
index 401830fccbc..8bb9f7b1ef7 100644
--- a/gcc/testsuite/gfortran.dg/init_flag_17.f90
+++ b/gcc/testsuite/gfortran.dg/init_flag_17.f90
@@ -19,8 +19,8 @@ program init_flag_17

    type(ty) :: t

-  print *, t%ptr
-  print *, t%fptr
+  print *, transfer(t%ptr, c_long_long)
+  print *, transfer(t%fptr, c_long_long)

  end program

Likewise.


diff --git a/gcc/testsuite/gfortran.dg/pr32601_1.f03
b/gcc/testsuite/gfortran.dg/pr32601_1.f03
index a297e1728ec..1a48419112d 100644
--- a/gcc/testsuite/gfortran.dg/pr32601_1.f03
+++ b/gcc/testsuite/gfortran.dg/pr32601_1.f03
@@ -4,9 +4,9 @@
  ! PR fortran/32601
  use, intrinsic :: iso_c_binding, only: c_loc, c_ptr
  implicit none
-
+integer i
  ! This was causing an ICE, but is an error because the argument to C_LOC
  ! needs to be a variable.
-print *, c_loc(4) ! { dg-error "shall have either the POINTER or the
TARGET attribute" }
+i = c_loc(4) ! { dg-error "shall have either the POINTER or the TARGET
attribute" }

  end

Again, i should be declared as type(c_ptr).

Cheers,
Harald


Regards,

Jerry


Author: Jerry DeLisle 
Date:   Tue Feb 11 20:57:50 2025 -0800

 Fortran:  gfortran allows type(C_ptr) in I/O list

 Before this patch, gfortran was accepting invalid use of
 type(c_ptr) in I/O statements. The fix affects several
 existing test cases so no new test case needed.

 Existing tests were modified to pass by either using the
 transfer function to convert to an acceptable value or
 using an assignment to a like type (non-I/O).

 PR fortran/117430

 gcc/fortran/ChangeLog:

 * resolve.cc (resolve_transfer): Issue the error
 with no exceptions allowed.

 gcc/testsuite/ChangeLog:

 * gfortran.dg/c_loc_test_17.f90: Modify to pass.
 * gfortran.dg/c_ptr_tests_10.f03: Likewise.
 * gfortran.dg/c_ptr_tes