Re: [PATCH] Fortran : Two further previously missed ICEs PR53298

2020-10-13 Thread Mark Eggleston

**ping**

see https://gcc.gnu.org/pipermail/gcc-patches/2020-September/554034.html 
and https://gcc.gnu.org/pipermail/gcc-patches/2020-September/555072.html


OK for master?

On 14/09/2020 08:22, Mark Eggleston wrote:

Second attempt this time with patch attached.

For review.

Fixes the two ICEs reported in PR that remained after the previous fix.

There is a side affect that is manifested in the tree dumps. Instead of

__builtin_free (ptr2->dat.data);

we get

__builtin_free ((void *) ptr2->dat.data);

I do not know the cause of this but from what I can tell the newly 
inserted cast is harmless.  All the examples I've seen so have the 
cast except where the parameter is declared as void *. In the tree 
dumps ptr2 is declared as struct testtype2 *, I do not know where the 
type is declared so I don't know whether data is declared void * (I 
expect it is).


Is it worth the effort to determine how to remove the extra (void *)?

[PATCH] Fortran  : Two further previously missed ICEs PR53298

There were 3 ICEs with different call stacks in the comments of this
PR.  A previous commit fixed only one of those ICEs.

The ICEs fixed here are in trans-array.c and trans-expr.c.

The first ICE occurred when the array reference is not AR_ELEMENT
gfc_conv_scalarized_array_ref is called with se and ar, if se->ss is
NULL the ICE occurs.  If se->ss is NULL there is nothing to do before
the return.

The second ICE occurs in code that did not match its comments. Fixing
the code to match the comments fixes the ICE.  A side affect is that
the in the tree dumps for finalize_35.f90 and finalize_36.f90 contain
"__builtin_free ((void *) ptr2->dat.data);", the "(void *)" was
previously omitted.  The cast is harmless.

2020-09-11  Mark Eggleston 

gcc/fortran/

    PR fortran/53298
    * trans-array.c (gfc_conv_array_ref): In the body of the if
    statement only execute the code before the reurn is se->ss is
    set.
    * trans-expr.c (gfc_conv_component_ref): Change the if
    expression to match the comments.

2020-09-04  Mark Eggleston 

gcc/testsuite/

    PR fortran/53298
    * gfortran.dg/finalize_35.f90: Handle extra (void *).
    * gfortran.dg/finalize_36.f90: Handle extra (void *).
    * gfortran.dg/pr53298_2.f90: New test.
    * gfortran.dg/pr53298_3.f90: New test.


--
https://www.codethink.co.uk/privacy.html



Re: [PATCH] Fortran : Two further previously missed ICEs PR53298

2020-09-29 Thread Mark Eggleston



On 16/09/2020 08:02, Andre Vehreschild wrote:

Hi Mark,

a few remarks:

[...]


[PATCH] Fortran  : Two further previously missed ICEs PR53298

There were 3 ICEs with different call stacks in the comments of this
PR.  A previous commit fixed only one of those ICEs.

The ICEs fixed here are in trans-array.c and trans-expr.c.

The first ICE occurred when the array reference is not AR_ELEMENT
gfc_conv_scalarized_array_ref is called with se and ar, if se->ss is
NULL the ICE occurs.  If se->ss is NULL there is nothing to do before
the return.

The second ICE occurs in code that did not match its comments.  Fixing
the code to match the comments fixes the ICE.  A side affect is that
the in the tree dumps for finalize_35.f90 and finalize_36.f90 contain

   ^^^
   Spurious "the" found.

wording has been updated.


[...]

diff --git a/gcc/fortran/trans-array.c b/gcc/fortran/trans-array.c
index 6566c47d4ae..06268739515 100644
--- a/gcc/fortran/trans-array.c
+++ b/gcc/fortran/trans-array.c
@@ -3638,8 +3638,11 @@ gfc_conv_array_ref (gfc_se * se, gfc_array_ref *
ar, gfc_expr *expr, /* Handle scalarized references separately.  */
if (ar->type != AR_ELEMENT)
  {
-  gfc_conv_scalarized_array_ref (se, ar);
-  gfc_advance_se_ss_chain (se);
+  if (se->ss)
+   {
+ gfc_conv_scalarized_array_ref (se, ar);
+ gfc_advance_se_ss_chain (se);
+   }

Why is this only in element ref needed and not every else? When I tried
to fix ICEs this way, I was usually asked if was fixing symptom and not
the error.


This is for references that aren't elements. As I understand it se 
corresponds to the upper bound, e.g. for a(1:) the upper bound may not 
be known at this point so se is NULL resulting in a crash due to it 
being de-referenced in gfc_conv_scalarized_array_ref.




return;
  }
  
diff --git a/gcc/fortran/trans-expr.c b/gcc/fortran/trans-expr.c

index 36ff9b5cbc6..193553ace0b 100644
--- a/gcc/fortran/trans-expr.c
+++ b/gcc/fortran/trans-expr.c
@@ -2474,8 +2474,8 @@ gfc_conv_component_ref (gfc_se * se, gfc_ref *
ref) RECORD_TYPE within a UNION_TYPE) always use the given FIELD_DECL.
*/
if (context != TREE_TYPE (decl)
-  && !(   TREE_CODE (TREE_TYPE (field)) == UNION_TYPE /* Field is
union */
-   || TREE_CODE (context) == UNION_TYPE)) /* Field is
map */
+  && (   TREE_CODE (context) == UNION_TYPE /* Field is union */
+  || TREE_CODE (context) == MAP_TYPE)) /* Field is map */
  {
tree f2 = c->norestrict_decl;
if (!f2 || DECL_FIELD_CONTEXT (f2) != TREE_TYPE (decl))

(Sorry for the line breaks).

I can't help it, but the old code looked so dubious that I wonder why
it worked in the first place. Have you tried with a mapped type?

structure /st/
  union
    map
  character(5) a, b
    end map
    map
  character(10) c
    end map
  end union
end structure

record /st/ r

r.c = "abcde12345"
write(*,*) r.a(2:), r.b(3:), r.c(6:)

end

outputs (as expected) with and without the patch

 bcde34512345

I can add this as an extra test case if required.



Regards,
Andre



--
https://www.codethink.co.uk/privacy.html



Re: [PATCH] Fortran : Two further previously missed ICEs PR53298

2020-09-16 Thread Andre Vehreschild
Hi Mark,

a few remarks:

[...]

> [PATCH] Fortran  : Two further previously missed ICEs PR53298
> 
> There were 3 ICEs with different call stacks in the comments of this
> PR.  A previous commit fixed only one of those ICEs.
> 
> The ICEs fixed here are in trans-array.c and trans-expr.c.
> 
> The first ICE occurred when the array reference is not AR_ELEMENT
> gfc_conv_scalarized_array_ref is called with se and ar, if se->ss is
> NULL the ICE occurs.  If se->ss is NULL there is nothing to do before
> the return.
> 
> The second ICE occurs in code that did not match its comments.  Fixing
> the code to match the comments fixes the ICE.  A side affect is that
> the in the tree dumps for finalize_35.f90 and finalize_36.f90 contain
  ^^^
  Spurious "the" found.

[...]

diff --git a/gcc/fortran/trans-array.c b/gcc/fortran/trans-array.c
index 6566c47d4ae..06268739515 100644
--- a/gcc/fortran/trans-array.c
+++ b/gcc/fortran/trans-array.c
@@ -3638,8 +3638,11 @@ gfc_conv_array_ref (gfc_se * se, gfc_array_ref *
ar, gfc_expr *expr, /* Handle scalarized references separately.  */
   if (ar->type != AR_ELEMENT)
 {
-  gfc_conv_scalarized_array_ref (se, ar);
-  gfc_advance_se_ss_chain (se);
+  if (se->ss)
+   {
+ gfc_conv_scalarized_array_ref (se, ar);
+ gfc_advance_se_ss_chain (se);
+   }

Why is this only in element ref needed and not every else? When I tried
to fix ICEs this way, I was usually asked if was fixing symptom and not
the error.

   return;
 }
 
diff --git a/gcc/fortran/trans-expr.c b/gcc/fortran/trans-expr.c
index 36ff9b5cbc6..193553ace0b 100644
--- a/gcc/fortran/trans-expr.c
+++ b/gcc/fortran/trans-expr.c
@@ -2474,8 +2474,8 @@ gfc_conv_component_ref (gfc_se * se, gfc_ref *
ref) RECORD_TYPE within a UNION_TYPE) always use the given FIELD_DECL.
*/ 
   if (context != TREE_TYPE (decl)
-  && !(   TREE_CODE (TREE_TYPE (field)) == UNION_TYPE /* Field is
union */
-   || TREE_CODE (context) == UNION_TYPE)) /* Field is
map */
+  && (   TREE_CODE (context) == UNION_TYPE /* Field is union */
+  || TREE_CODE (context) == MAP_TYPE)) /* Field is map */
 {
   tree f2 = c->norestrict_decl;
   if (!f2 || DECL_FIELD_CONTEXT (f2) != TREE_TYPE (decl))

(Sorry for the line breaks).

I can't help it, but the old code looked so dubious that I wonder why
it worked in the first place. Have you tried with a mapped type?

Regards,
Andre


-- 
Andre Vehreschild * ve...@gmx.de


[PATCH] Fortran : Two further previously missed ICEs PR53298

2020-09-14 Thread Mark Eggleston

Second attempt this time with patch attached.

For review.

Fixes the two ICEs reported in PR that remained after the previous fix.

There is a side affect that is manifested in the tree dumps. Instead of

__builtin_free (ptr2->dat.data);

we get

__builtin_free ((void *) ptr2->dat.data);

I do not know the cause of this but from what I can tell the newly 
inserted cast is harmless.  All the examples I've seen so have the cast 
except where the parameter is declared as void *. In the tree dumps ptr2 
is declared as struct testtype2 *, I do not know where the type is 
declared so I don't know whether data is declared void * (I expect it is).


Is it worth the effort to determine how to remove the extra (void *)?

[PATCH] Fortran  : Two further previously missed ICEs PR53298

There were 3 ICEs with different call stacks in the comments of this
PR.  A previous commit fixed only one of those ICEs.

The ICEs fixed here are in trans-array.c and trans-expr.c.

The first ICE occurred when the array reference is not AR_ELEMENT
gfc_conv_scalarized_array_ref is called with se and ar, if se->ss is
NULL the ICE occurs.  If se->ss is NULL there is nothing to do before
the return.

The second ICE occurs in code that did not match its comments.  Fixing
the code to match the comments fixes the ICE.  A side affect is that
the in the tree dumps for finalize_35.f90 and finalize_36.f90 contain
"__builtin_free ((void *) ptr2->dat.data);", the "(void *)" was
previously omitted.  The cast is harmless.

2020-09-11  Mark Eggleston 

gcc/fortran/

    PR fortran/53298
    * trans-array.c (gfc_conv_array_ref): In the body of the if
    statement only execute the code before the reurn is se->ss is
    set.
    * trans-expr.c (gfc_conv_component_ref): Change the if
    expression to match the comments.

2020-09-04  Mark Eggleston 

gcc/testsuite/

    PR fortran/53298
    * gfortran.dg/finalize_35.f90: Handle extra (void *).
    * gfortran.dg/finalize_36.f90: Handle extra (void *).
    * gfortran.dg/pr53298_2.f90: New test.
    * gfortran.dg/pr53298_3.f90: New test.

--

https://www.codethink.co.uk/privacy.html

>From b88c7fdae5e76e5d47086f124357cee7159bc6fd Mon Sep 17 00:00:00 2001
From: Mark Eggleston 
Date: Tue, 8 Sep 2020 14:28:18 +0100
Subject: [PATCH] Fortran  : Two further previously missed ICEs PR53298

There were 3 ICEs with different call stacks in the comments of this
PR.  A previous commit fixed only one of those ICEs.

The ICEs fixed here are in trans-array.c and trans-expr.c.

The first ICE occurred when the array reference is not AR_ELEMENT
gfc_conv_scalarized_array_ref is called with se and ar, if se->ss is
NULL the ICE occurs.  If se->ss is NULL there is nothing to do before
the return.

The second ICE occurs in code that did not match its comments.  Fixing
the code to match the comments fixes the ICE.  A side affect is that
the in the tree dumps for finalize_35.f90 and finalize_36.f90 contain
"__builtin_free ((void *) ptr2->dat.data);", the "(void *)" was
previously omitted.  The cast is harmless.

2020-09-11  Mark Eggleston  

gcc/fortran/

	PR fortran/53298
	* trans-array.c (gfc_conv_array_ref): In the body of the if
	statement only execute the code before the reurn is se->ss is
	set.
	* trans-expr.c (gfc_conv_component_ref): Change the if
	expression to match the comments.

2020-09-04  Mark Eggleston  

gcc/testsuite/

	PR fortran/53298
	* gfortran.dg/finalize_35.f90: Handle extra (void *).
	* gfortran.dg/finalize_36.f90: Handle extra (void *).
	* gfortran.dg/pr53298_2.f90: New test.
	* gfortran.dg/pr53298_3.f90: New test.
---
 gcc/fortran/trans-array.c |  7 +--
 gcc/fortran/trans-expr.c  |  4 ++--
 gcc/testsuite/gfortran.dg/finalize_35.f90 |  2 +-
 gcc/testsuite/gfortran.dg/finalize_36.f90 |  2 +-
 gcc/testsuite/gfortran.dg/pr53298_2.f90   | 16 
 gcc/testsuite/gfortran.dg/pr53298_3.f90   | 31 +++
 6 files changed, 56 insertions(+), 6 deletions(-)
 create mode 100644 gcc/testsuite/gfortran.dg/pr53298_2.f90
 create mode 100644 gcc/testsuite/gfortran.dg/pr53298_3.f90

diff --git a/gcc/fortran/trans-array.c b/gcc/fortran/trans-array.c
index 6566c47d4ae..06268739515 100644
--- a/gcc/fortran/trans-array.c
+++ b/gcc/fortran/trans-array.c
@@ -3638,8 +3638,11 @@ gfc_conv_array_ref (gfc_se * se, gfc_array_ref * ar, gfc_expr *expr,
   /* Handle scalarized references separately.  */
   if (ar->type != AR_ELEMENT)
 {
-  gfc_conv_scalarized_array_ref (se, ar);
-  gfc_advance_se_ss_chain (se);
+  if (se->ss)
+	{
+	  gfc_conv_scalarized_array_ref (se, ar);
+	  gfc_advance_se_ss_chain (se);
+	}
   return;
 }
 
diff --git a/gcc/fortran/trans-expr.c b/gcc/fortran/trans-expr.c
index 36ff9b5cbc6..193553ace0b 100644
--- a/gcc/fortran/trans-expr.c
+++ b/gcc/fortran/trans-expr.c
@@ -2474,8 +2474,8 @@ gfc_conv_component_ref (gfc_se * se, gfc_re

[PATCH] Fortran : Two further previously missed ICEs PR53298

2020-09-11 Thread Mark Eggleston

For review.

Fixes the two ICEs reported in PR that remained after the previous fix.

There is a side affect that is manifested in the tree dumps. Instead of

__builtin_free (ptr2->dat.data);

we get

__builtin_free ((void *) ptr2->dat.data);

I do not know the cause of this but from what I can tell the newly 
inserted cast is harmless.  All the examples I've seen so have the cast 
except where the parameter is declared as void *. In the tree dumps ptr2 
is declared as struct testtype2 *, I do not know where the type is 
declared so I don't know whether data is declared void * (I expect it is).


Is it worth the effort to determine how to remove the extra (void *)?

[PATCH] Fortran  : Two further previously missed ICEs PR53298

There were 3 ICEs with different call stacks in the comments of this
PR.  A previous commit fixed only one of those ICEs.

The ICEs fixed here are in trans-array.c and trans-expr.c.

The first ICE occurred when the array reference is not AR_ELEMENT
gfc_conv_scalarized_array_ref is called with se and ar, if se->ss is
NULL the ICE occurs.  If se->ss is NULL there is nothing to do before
the return.

The second ICE occurs in code that did not match its comments.  Fixing
the code to match the comments fixes the ICE.  A side affect is that
the in the tree dumps for finalize_35.f90 and finalize_36.f90 contain
"__builtin_free ((void *) ptr2->dat.data);", the "(void *)" was
previously omitted.  The cast is harmless.

2020-09-11  Mark Eggleston 

gcc/fortran/

    PR fortran/53298
    * trans-array.c (gfc_conv_array_ref): In the body of the if
    statement only execute the code before the reurn is se->ss is
    set.
    * trans-expr.c (gfc_conv_component_ref): Change the if
    expression to match the comments.

2020-09-04  Mark Eggleston 

gcc/testsuite/

    PR fortran/53298
    * gfortran.dg/finalize_35.f90: Handle extra (void *).
    * gfortran.dg/finalize_36.f90: Handle extra (void *).
    * gfortran.dg/pr53298_2.f90: New test.
    * gfortran.dg/pr53298_3.f90: New test.

--
https://www.codethink.co.uk/privacy.html