Re: [Patch, fortran v2] PR fortran/84006, PR fortran/100027 - ICE on storage_size with polymorphic argument

2021-04-17 Thread Paul Richard Thomas via Fortran
Hi Jose,

Please take a look at my reply on the PR, which points to PR98534.

Regards

Paul


On Fri, 16 Apr 2021 at 20:47, José Rui Faustino de Sousa via Fortran <
fortran@gcc.gnu.org> wrote:

> Hi All!
>
> Proposed patch to:
> PR84006 - [8/9/10/11 Regression] ICE in storage_size() with CLASS entity
> PR100027 - ICE on storage_size with polymorphic argument
>
> Patch tested only on x86_64-pc-linux-gnu.
>
> Add branch to if clause to handle polymorphic objects, not sure if I got
> all possible variations...
>
> Now with a new and extended test.
>
> Thank you very much.
>
> Best regards,
> José Rui
>
> Fortran: Fix ICE using storage_size intrinsic [PR84006, PR100027]
>
> gcc/fortran/ChangeLog:
>
>  PR fortran/84006
>  PR fortran/100027
>  * trans-intrinsic.c (gfc_conv_intrinsic_storage_size): add if
>  clause branch to handle polymorphic objects.
>
> gcc/testsuite/ChangeLog:
>
>  PR fortran/84006
>  * gfortran.dg/PR84006.f90: New test.
>
>  PR fortran/100027
>  * gfortran.dg/PR100027.f90: New test.
>


-- 
"If you can't explain it simply, you don't understand it well enough" -
Albert Einstein


[Patch, fortran] PR fortran/100132 - Optimization breaks pointer association

2021-04-17 Thread José Rui Faustino de Sousa via Fortran

Hi All!

Proposed patch to:

PR100132 - Optimization breaks pointer association.

Patch tested only on x86_64-pc-linux-gnu.

Correct pointer attributes when passing polymorphic pointers.

Thank you very much.

Best regards,
José Rui

Fortran: Fix function attributes [PR100132]

gcc/fortran/ChangeLog:

PR fortran/100132
* trans-types.c (create_fn_spec): fix function attributes when
passing polymorphic pointers.

gcc/testsuite/ChangeLog:

PR fortran/100132
* gfortran.dg/PR100132.f90: New test.

diff --git a/gcc/fortran/trans-types.c b/gcc/fortran/trans-types.c
index 9f21b3ee780..6cf85dc9a41 100644
--- a/gcc/fortran/trans-types.c
+++ b/gcc/fortran/trans-types.c
@@ -2981,12 +2981,25 @@ create_fn_spec (gfc_symbol *sym, tree fntype)
   for (f = gfc_sym_get_dummy_args (sym); f; f = f->next)
 if (spec_len < sizeof (spec))
   {
-	if (!f->sym || f->sym->attr.pointer || f->sym->attr.target
+	bool is_class = false;
+	bool is_pointer = false;
+
+	if (f->sym)
+	  {
+	symbol_attribute *attr = NULL;
+
+	is_class = f->sym->ts.type == BT_CLASS && CLASS_DATA (f->sym)
+	  && f->sym->attr.class_ok;
+	attr = is_class ? &(CLASS_DATA (f->sym)->attr) : &(f->sym->attr);
+	is_pointer = is_class ? attr->class_pointer : attr->pointer;
+	  }
+
+	if (f->sym == NULL || is_pointer || f->sym->attr.target
 	|| f->sym->attr.external || f->sym->attr.cray_pointer
 	|| (f->sym->ts.type == BT_DERIVED
 		&& (f->sym->ts.u.derived->attr.proc_pointer_comp
 		|| f->sym->ts.u.derived->attr.pointer_comp))
-	|| (f->sym->ts.type == BT_CLASS
+	|| (is_class
 		&& (CLASS_DATA (f->sym)->ts.u.derived->attr.proc_pointer_comp
 		|| CLASS_DATA (f->sym)->ts.u.derived->attr.pointer_comp))
 	|| (f->sym->ts.type == BT_INTEGER && f->sym->ts.is_c_interop))
diff --git a/gcc/testsuite/gfortran.dg/PR100132.f90 b/gcc/testsuite/gfortran.dg/PR100132.f90
new file mode 100644
index 000..aec0fef3d26
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/PR100132.f90
@@ -0,0 +1,81 @@
+! { dg-do run }
+!
+! Test the fix for PR100132
+!
+
+module main_m
+
+  implicit none
+
+  private
+
+  public :: &
+foo_t
+
+  public :: &
+set,&
+get
+  
+  type :: foo_t
+!private
+integer :: i
+  end type foo_t
+
+  type(foo_t), save, pointer :: data => null()
+  
+contains
+
+  subroutine set(this)
+class(foo_t), pointer, intent(in) :: this
+
+if(associated(data)) stop 1
+data => this
+return
+  end subroutine set
+
+  subroutine get(this)
+type(foo_t), pointer, intent(out) :: this
+
+if(.not.associated(data)) stop 4
+this => data
+nullify(data)
+return
+  end subroutine get
+
+end module main_m
+
+program main_p
+
+  use :: main_m, only: &
+foo_t, set, get
+
+  implicit none
+
+  integer, parameter :: n = 1000
+
+  type(foo_t), pointer :: ps
+  type(foo_t),  target :: s
+  integer  :: i, j, yay, nay
+
+  yay = 0
+  nay = 0
+  do i = 1, n
+s%i = i
+call set(s)
+call get(ps)
+if(.not.associated(ps)) stop 13
+j = ps%i
+if(i/=j) stop 14
+if(i/=s%i) stop 15
+if(ps%i/=s%i) stop 16
+if(associated(ps, s))then
+  yay = yay + 1
+else
+  nay = nay + 1
+end if
+  end do
+  if((yay/=n).or.(nay/=0)) stop 17
+  stop
+
+end program main_p
+


Re: [PATCH] docs: Remove empty table column.

2021-04-17 Thread Gerald Pfeifer
On Mon, 12 Apr 2021, Martin Liška wrote:
> A column with empty values seems suspicious.
>
> Ready to be installed?

Yes, if you've been able to validate this visually (before/after).

Please give the Fortran folks the rest of the weekend/another 24h
to chim in.

> gcc/fortran/ChangeLog:
> 
>   * intrinsic.texi: The table has first column empty and it makes
>   trouble when processing makeinfo --xml output.

Gerald