public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] PR fortran/104210 - [11/12 Regression] ICE in gfc_zero_size_array, at fortran/arith.cc:1685
@ 2022-03-29 21:41 Harald Anlauf
  2022-04-04 19:09 ` *Ping* " Harald Anlauf
  0 siblings, 1 reply; 4+ messages in thread
From: Harald Anlauf @ 2022-03-29 21:41 UTC (permalink / raw)
  To: fortran, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 286 bytes --]

Dear all,

during error recovery on invalid declarations of functions as
coarrays we may hit multiple places with NULL pointer dereferences.
The attached patch provides a minimal and conservative solution.

Regtested on x86_64-pc-linux-gnu.  OK for mainline/11-branch?

Thanks,
Harald


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Fortran-improve-error-recovery-for-invalid-coarray-f.patch --]
[-- Type: text/x-patch, Size: 2017 bytes --]

From ce80d4b2ce3f35684f09bbb2f95f6edc5827224b Mon Sep 17 00:00:00 2001
From: Harald Anlauf <anlauf@gmx.de>
Date: Tue, 29 Mar 2022 23:33:23 +0200
Subject: [PATCH] Fortran: improve error recovery for invalid coarray function
 declarations

gcc/fortran/ChangeLog:

	PR fortran/104210
	* arith.cc (eval_intrinsic): Avoid NULL pointer dereference.
	(gfc_zero_size_array): Likewise.

gcc/testsuite/ChangeLog:

	PR fortran/104210
	* gfortran.dg/pr104210.f90: New test.
---
 gcc/fortran/arith.cc                   |  9 ++++++---
 gcc/testsuite/gfortran.dg/pr104210.f90 | 15 +++++++++++++++
 2 files changed, 21 insertions(+), 3 deletions(-)
 create mode 100644 gcc/testsuite/gfortran.dg/pr104210.f90

diff --git a/gcc/fortran/arith.cc b/gcc/fortran/arith.cc
index 06e032e22db..d57059a375f 100644
--- a/gcc/fortran/arith.cc
+++ b/gcc/fortran/arith.cc
@@ -1489,6 +1489,9 @@ eval_intrinsic (gfc_intrinsic_op op,
   int unary;
   arith rc;

+  if (!op1)
+    return NULL;
+
   gfc_clear_ts (&temp.ts);

   switch (op)
@@ -1703,11 +1706,11 @@ eval_type_intrinsic0 (gfc_intrinsic_op iop, gfc_expr *op)

 /* Return nonzero if the expression is a zero size array.  */

-static int
+static bool
 gfc_zero_size_array (gfc_expr *e)
 {
-  if (e->expr_type != EXPR_ARRAY)
-    return 0;
+  if (e == NULL || e->expr_type != EXPR_ARRAY)
+    return false;

   return e->value.constructor == NULL;
 }
diff --git a/gcc/testsuite/gfortran.dg/pr104210.f90 b/gcc/testsuite/gfortran.dg/pr104210.f90
new file mode 100644
index 00000000000..182404c265b
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr104210.f90
@@ -0,0 +1,15 @@
+! { dg-do compile }
+! { dg-options "-fcoarray=single" }
+! PR fortran/104210
+! Contributed by G.Steinmetz
+
+function f()      ! { dg-error "shall not be a coarray" }
+  integer :: f[*]
+end
+program p
+  interface
+     function f() ! { dg-error "shall not be a coarray" }
+       integer :: f[*]
+     end
+  end interface
+end
--
2.34.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* *Ping* [PATCH] PR fortran/104210 - [11/12 Regression] ICE in gfc_zero_size_array, at fortran/arith.cc:1685
  2022-03-29 21:41 [PATCH] PR fortran/104210 - [11/12 Regression] ICE in gfc_zero_size_array, at fortran/arith.cc:1685 Harald Anlauf
@ 2022-04-04 19:09 ` Harald Anlauf
  2022-04-04 19:09   ` Harald Anlauf
  2022-04-05  1:18   ` Jerry D
  0 siblings, 2 replies; 4+ messages in thread
From: Harald Anlauf @ 2022-04-04 19:09 UTC (permalink / raw)
  To: fortran, gcc-patches

Am 29.03.22 um 23:41 schrieb Harald Anlauf via Fortran:
> Dear all,
>
> during error recovery on invalid declarations of functions as
> coarrays we may hit multiple places with NULL pointer dereferences.
> The attached patch provides a minimal and conservative solution.
>
> Regtested on x86_64-pc-linux-gnu.  OK for mainline/11-branch?
>
> Thanks,
> Harald
>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* *Ping* [PATCH] PR fortran/104210 - [11/12 Regression] ICE in gfc_zero_size_array, at fortran/arith.cc:1685
  2022-04-04 19:09 ` *Ping* " Harald Anlauf
@ 2022-04-04 19:09   ` Harald Anlauf
  2022-04-05  1:18   ` Jerry D
  1 sibling, 0 replies; 4+ messages in thread
From: Harald Anlauf @ 2022-04-04 19:09 UTC (permalink / raw)
  To: fortran; +Cc: gcc-patches

Am 29.03.22 um 23:41 schrieb Harald Anlauf via Fortran:
> Dear all,
> 
> during error recovery on invalid declarations of functions as
> coarrays we may hit multiple places with NULL pointer dereferences.
> The attached patch provides a minimal and conservative solution.
> 
> Regtested on x86_64-pc-linux-gnu.  OK for mainline/11-branch?
> 
> Thanks,
> Harald
> 



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: *Ping* [PATCH] PR fortran/104210 - [11/12 Regression] ICE in gfc_zero_size_array, at fortran/arith.cc:1685
  2022-04-04 19:09 ` *Ping* " Harald Anlauf
  2022-04-04 19:09   ` Harald Anlauf
@ 2022-04-05  1:18   ` Jerry D
  1 sibling, 0 replies; 4+ messages in thread
From: Jerry D @ 2022-04-05  1:18 UTC (permalink / raw)
  To: Harald Anlauf, fortran, gcc-patches

On 4/4/22 12:09 PM, Harald Anlauf via Fortran wrote:
> Am 29.03.22 um 23:41 schrieb Harald Anlauf via Fortran:
>> Dear all,
>>
>> during error recovery on invalid declarations of functions as
>> coarrays we may hit multiple places with NULL pointer dereferences.
>> The attached patch provides a minimal and conservative solution.
>>
>> Regtested on x86_64-pc-linux-gnu.  OK for mainline/11-branch?
>>
>> Thanks,
>> Harald
>>
>
Patch looks OK Harald, OK.

Thanks,

Jerry


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-04-05  1:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-29 21:41 [PATCH] PR fortran/104210 - [11/12 Regression] ICE in gfc_zero_size_array, at fortran/arith.cc:1685 Harald Anlauf
2022-04-04 19:09 ` *Ping* " Harald Anlauf
2022-04-04 19:09   ` Harald Anlauf
2022-04-05  1:18   ` Jerry D

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).