Re: [Patch, fortran] PR109066 - Segfault when using defined assignment

2024-11-16 Thread Paul Richard Thomas
Hi Thomas,

This has to be the shortest interval between submission and pushing of a
patch that I have experienced!

Pushed to mainline as r15-5347...

Thanks for the review!

Paul


On Sat, 16 Nov 2024 at 15:46, Thomas Koenig  wrote:

> Hi Paul,
>
>
> > This is a particularly straightforward, going on 'obvious',  patch. The
> > bug goes back to at least gcc-6.4.1.
> >
> > OK for mainline and, after a week or two, to 13- and 14-branches?
>
> As you say, this one is straightforward.
>
> OK for trunk and as far back as you care to backport.
>
> Thanks for the patch!
>
> Best regards
>
> Thomas
>
>
>


[patch, fortran, doc, committed] Mention that SELECT CASE works for unsigned

2024-11-16 Thread Thomas Koenig

Hello world,

I just committed the attached documentatin patch as obvious,
in r15-5344-gbf00f117eb4b5527592029e39a3d79f2048745d8 .

Best regards

Thomas

Document that SELECT CASE works for unsigned.

gcc/fortran/ChangeLog:

* gfortran.texi: Document that SELECT CASE works for UNSIGNED.


diff --git a/gcc/fortran/gfortran.texi b/gcc/fortran/gfortran.texi
index a6617aa1571..c91d548fc55 100644
--- a/gcc/fortran/gfortran.texi
+++ b/gcc/fortran/gfortran.texi
@@ -2773,6 +2773,8 @@ formatted and unformatted I/O.  For formatted I/O, 
the @code{B},

 values and values which would overflow are rejected with
 @code{-pedantic}.

+@code{SELECT CASE} is supported for unsigned integers.
+
 The following intrinsics take unsigned arguments:
 @itemize @bullet
 @item @code{BGE}, @pxref{BGE}



Re: [Patch, fortran] PR109066 - Segfault when using defined assignment

2024-11-16 Thread Thomas Koenig

Hi Paul,


This is a particularly straightforward, going on 'obvious',  patch. The 
bug goes back to at least gcc-6.4.1.


OK for mainline and, after a week or two, to 13- and 14-branches?


As you say, this one is straightforward.

OK for trunk and as far back as you care to backport.

Thanks for the patch!

Best regards

Thomas




Re: [patch, Fortran, committed] Handle unsigned constants in modules

2024-11-16 Thread Steve Kargl
On Sat, Nov 16, 2024 at 02:55:11PM +0100, Thomas Koenig wrote:
> 
> Steve found a test case where unsigned constants were not handled
> in a module. Single-line patch committed as obvious and simple,
> r15-5341-g66096151afc6631f8f2a3458b154c5daa822b963 .
> 
> Best regards
> 
>   Thomas
> 

Thanks for the patch.

-- 
Steve


[patch, Fortran, committed] Handle unsigned constants in modules

2024-11-16 Thread Thomas Koenig

Hello world,

Steve found a test case where unsigned constants were not handled
in a module. Single-line patch committed as obvious and simple,
r15-5341-g66096151afc6631f8f2a3458b154c5daa822b963 .

Best regards

Thomas

Handle unsigned constants for module I/O.

gcc/fortran/ChangeLog:

* module.cc (mio_expr): Handle BT_UNSIGNED.

gcc/testsuite/ChangeLog:

* gfortran.dg/unsigned_42.f90: New test.
diff --git a/gcc/fortran/module.cc b/gcc/fortran/module.cc
index 9ab4d2bf1ea..d184dbc661f 100644
--- a/gcc/fortran/module.cc
+++ b/gcc/fortran/module.cc
@@ -3925,6 +3925,7 @@ mio_expr (gfc_expr **ep)
   switch (e->ts.type)
 	{
 	case BT_INTEGER:
+	case BT_UNSIGNED:
 	  mio_gmp_integer (&e->value.integer);
 	  break;
 
diff --git a/gcc/testsuite/gfortran.dg/unsigned_42.f90 b/gcc/testsuite/gfortran.dg/unsigned_42.f90
new file mode 100644
index 000..e9a723863c6
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/unsigned_42.f90
@@ -0,0 +1,12 @@
+! { dg-do compile }
+! { dg-options "-funsigned" }
+module mytype
+  integer, parameter :: uk = selected_unsigned_kind(12)
+end module mytype
+
+module foo
+  use mytype
+  implicit none
+  unsigned(uk), parameter :: seed0 = 1u_uk
+  unsigned(uk), protected :: x_ = seed0
+end module foo


[Patch, fortran] PR109066 - Segfault when using defined assignment

2024-11-16 Thread Paul Richard Thomas
Hi All,

This is a particularly straightforward, going on 'obvious',  patch. The bug
goes back to at least gcc-6.4.1.

OK for mainline and, after a week or two, to 13- and 14-branches?

Regards

Paul


Change.Logs
Description: Binary data
diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc
index b8c908b51e9..e8f780d1ef9 100644
--- a/gcc/fortran/resolve.cc
+++ b/gcc/fortran/resolve.cc
@@ -12404,6 +12404,11 @@ generate_component_assignments (gfc_code **code, gfc_namespace *ns)
 {
   /* Assign the rhs to the temporary.  */
   tmp_expr = get_temp_from_expr ((*code)->expr1, ns);
+  if (tmp_expr->symtree->n.sym->attr.pointer)
+	{
+	  tmp_expr->symtree->n.sym->attr.pointer = 0;
+	  tmp_expr->symtree->n.sym->attr.allocatable = 1;
+	}
   this_code = build_assignment (EXEC_ASSIGN,
 tmp_expr, (*code)->expr2,
 NULL, NULL, (*code)->loc);
diff --git a/gcc/testsuite/gfortran.dg/defined_assignment_12.f90 b/gcc/testsuite/gfortran.dg/defined_assignment_12.f90
new file mode 100644
index 000..57445abe25c
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/defined_assignment_12.f90
@@ -0,0 +1,61 @@
+! { dg-do run }
+!
+! Test fix of PR109066, which caused segfaults as below
+!
+! Contributed by Andrew Benson  
+!
+module bugMod
+
+  type :: rm
+ integer :: c=0
+   contains
+ procedure :: rma
+ generic   :: assignment(=) => rma
+  end type rm
+
+  type :: lc
+ type(rm) :: lm
+  end type lc
+
+contains
+
+  impure elemental subroutine rma(to,from)
+implicit none
+class(rm), intent(out) :: to
+class(rm), intent(in) :: from
+to%c = -from%c
+return
+  end subroutine rma
+
+end module bugMod
+
+program bug
+  use bugMod
+  implicit none
+  type(lc), pointer :: i, j(:)
+
+  allocate (i)
+  i = lc (rm (1))  ! Segmentation fault
+  if (i%lm%c .ne. -1) stop 1
+  i = i_ptr () ! Segmentation fault
+  if (i%lm%c .ne. 1) stop 2
+
+  allocate (j(2))
+  j = [lc (rm (2)), lc (rm (3))]   ! Segmentation fault
+  if (any (j%lm%c .ne. [-2,-3])) stop 3
+  j = j_ptr () ! Worked!
+  if (any (j%lm%c .ne. [2,3])) stop 4
+
+contains
+
+  function i_ptr () result(res)
+type(lc), pointer :: res
+res => i
+  end function
+
+  function j_ptr () result(res)
+type(lc), pointer :: res (:)
+res => j
+  end function
+
+end program bug