public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH, committed] Fortran: fix diagnostics for SELECT RANK [PR100607]
@ 2023-06-02 18:05 Harald Anlauf
  2023-06-03  5:48 ` Paul Richard Thomas
  0 siblings, 1 reply; 4+ messages in thread
From: Harald Anlauf @ 2023-06-02 18:05 UTC (permalink / raw)
  To: fortran, gcc-patches

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

Dear all,

I've committed that attached simple patch on behalf of Steve
after discussion in the PR and regtesting on x86_64-pc-linux-gnu.

It fixes a duplicate error message and an ICE.

Pushed as r14-1505-gfae09dfc0e6bf4cfe35d817558827aea78c6426f .

Thanks,
Harald


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: pr100607.diff --]
[-- Type: text/x-patch, Size: 3345 bytes --]

From fae09dfc0e6bf4cfe35d817558827aea78c6426f Mon Sep 17 00:00:00 2001
From: Steve Kargl <kargl@gcc.gnu.org>
Date: Fri, 2 Jun 2023 19:44:11 +0200
Subject: [PATCH] Fortran: fix diagnostics for SELECT RANK [PR100607]

gcc/fortran/ChangeLog:

	PR fortran/100607
	* resolve.cc (resolve_select_rank): Remove duplicate error.
	(resolve_fl_var_and_proc): Prevent NULL pointer dereference and
	suppress error message for temporary.

gcc/testsuite/ChangeLog:

	PR fortran/100607
	* gfortran.dg/select_rank_6.f90: New test.
---
 gcc/fortran/resolve.cc                      | 10 ++---
 gcc/testsuite/gfortran.dg/select_rank_6.f90 | 48 +++++++++++++++++++++
 2 files changed, 52 insertions(+), 6 deletions(-)
 create mode 100644 gcc/testsuite/gfortran.dg/select_rank_6.f90

diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc
index 2ba3101f1fe..fd059dddf05 100644
--- a/gcc/fortran/resolve.cc
+++ b/gcc/fortran/resolve.cc
@@ -10020,11 +10020,6 @@ resolve_select_rank (gfc_code *code, gfc_namespace *old_ns)
 			       || gfc_expr_attr (code->expr1).pointer))
 	gfc_error ("RANK (*) at %L cannot be used with the pointer or "
 		   "allocatable selector at %L", &c->where, &code->expr1->where);
-
-      if (case_value == -1 && (gfc_expr_attr (code->expr1).allocatable
-			       || gfc_expr_attr (code->expr1).pointer))
-	gfc_error ("RANK (*) at %L cannot be used with the pointer or "
-		   "allocatable selector at %L", &c->where, &code->expr1->where);
     }

   /* Add EXEC_SELECT to switch on rank.  */
@@ -13262,7 +13257,10 @@ resolve_fl_var_and_proc (gfc_symbol *sym, int mp_flag)

       if (allocatable)
 	{
-	  if (dimension && as->type != AS_ASSUMED_RANK)
+	  if (dimension
+	      && as
+	      && as->type != AS_ASSUMED_RANK
+	      && !sym->attr.select_rank_temporary)
 	    {
 	      gfc_error ("Allocatable array %qs at %L must have a deferred "
 			 "shape or assumed rank", sym->name, &sym->declared_at);
diff --git a/gcc/testsuite/gfortran.dg/select_rank_6.f90 b/gcc/testsuite/gfortran.dg/select_rank_6.f90
new file mode 100644
index 00000000000..d0121777bb5
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/select_rank_6.f90
@@ -0,0 +1,48 @@
+! { dg-do compile }
+! PR fortran/100607 - fix diagnostics for SELECT RANK
+! Contributed by T.Burnus
+
+program p
+  implicit none
+  integer, allocatable :: A(:,:,:)
+
+  allocate(a(5:6,-2:2, 99:100))
+  call foo(a)
+  call bar(a)
+
+contains
+
+  subroutine foo(x)
+    integer, allocatable :: x(..)
+    if (rank(x) /= 3) stop 1
+    if (any (lbound(x) /= [5, -2, 99])) stop 2
+
+    select rank (x)
+    rank(3)
+      if (any (lbound(x) /= [5, -2, 99])) stop 3
+    end select
+
+    select rank (x) ! { dg-error "pointer or allocatable selector at .2." }
+    rank(*)         ! { dg-error "pointer or allocatable selector at .2." }
+      if (rank(x) /= 1) stop 4
+      if (lbound(x, 1) /= 1) stop 5
+    end select
+  end
+
+  subroutine bar(x)
+    integer :: x(..)
+    if (rank(x) /= 3) stop 6
+    if (any (lbound(x) /= 1)) stop 7
+
+    select rank (x)
+    rank(3)
+      if (any (lbound(x) /= 1)) stop 8
+    end select
+
+    select rank (x)
+    rank(*)
+      if (rank(x) /= 1) stop 9
+      if (lbound(x, 1) /= 1) stop 10
+    end select
+  end
+end
--
2.35.3


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

* Re: [PATCH, committed] Fortran: fix diagnostics for SELECT RANK [PR100607]
  2023-06-02 18:05 [PATCH, committed] Fortran: fix diagnostics for SELECT RANK [PR100607] Harald Anlauf
@ 2023-06-03  5:48 ` Paul Richard Thomas
  2023-06-03 19:13   ` Harald Anlauf
  0 siblings, 1 reply; 4+ messages in thread
From: Paul Richard Thomas @ 2023-06-03  5:48 UTC (permalink / raw)
  To: Harald Anlauf; +Cc: fortran, gcc-patches

Hi Harald,

It looks good to me. Thanks to you and Steve for the fix. I suggest
that it is such and obvious one that it deserved back-porting.

Cheers

Paul

On Fri, 2 Jun 2023 at 19:06, Harald Anlauf via Fortran
<fortran@gcc.gnu.org> wrote:
>
> Dear all,
>
> I've committed that attached simple patch on behalf of Steve
> after discussion in the PR and regtesting on x86_64-pc-linux-gnu.
>
> It fixes a duplicate error message and an ICE.
>
> Pushed as r14-1505-gfae09dfc0e6bf4cfe35d817558827aea78c6426f .
>
> Thanks,
> Harald
>


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

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

* Re: [PATCH, committed] Fortran: fix diagnostics for SELECT RANK [PR100607]
  2023-06-03  5:48 ` Paul Richard Thomas
@ 2023-06-03 19:13   ` Harald Anlauf
  2023-06-03 19:13     ` Harald Anlauf
  0 siblings, 1 reply; 4+ messages in thread
From: Harald Anlauf @ 2023-06-03 19:13 UTC (permalink / raw)
  To: Paul Richard Thomas; +Cc: fortran, gcc-patches

Hi Paul,

On 6/3/23 07:48, Paul Richard Thomas via Gcc-patches wrote:
> Hi Harald,
>
> It looks good to me. Thanks to you and Steve for the fix. I suggest
> that it is such and obvious one that it deserved back-porting.

alright, I'll check how far this makes sense.

Cheers,
Harald

> Cheers
>
> Paul
>
> On Fri, 2 Jun 2023 at 19:06, Harald Anlauf via Fortran
> <fortran@gcc.gnu.org> wrote:
>>
>> Dear all,
>>
>> I've committed that attached simple patch on behalf of Steve
>> after discussion in the PR and regtesting on x86_64-pc-linux-gnu.
>>
>> It fixes a duplicate error message and an ICE.
>>
>> Pushed as r14-1505-gfae09dfc0e6bf4cfe35d817558827aea78c6426f .
>>
>> Thanks,
>> Harald
>>
>
>


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

* Re: [PATCH, committed] Fortran: fix diagnostics for SELECT RANK [PR100607]
  2023-06-03 19:13   ` Harald Anlauf
@ 2023-06-03 19:13     ` Harald Anlauf
  0 siblings, 0 replies; 4+ messages in thread
From: Harald Anlauf @ 2023-06-03 19:13 UTC (permalink / raw)
  To: fortran; +Cc: gcc-patches, fortran

Hi Paul,

On 6/3/23 07:48, Paul Richard Thomas via Gcc-patches wrote:
> Hi Harald,
> 
> It looks good to me. Thanks to you and Steve for the fix. I suggest
> that it is such and obvious one that it deserved back-porting.

alright, I'll check how far this makes sense.

Cheers,
Harald

> Cheers
> 
> Paul
> 
> On Fri, 2 Jun 2023 at 19:06, Harald Anlauf via Fortran
> <fortran@gcc.gnu.org> wrote:
>>
>> Dear all,
>>
>> I've committed that attached simple patch on behalf of Steve
>> after discussion in the PR and regtesting on x86_64-pc-linux-gnu.
>>
>> It fixes a duplicate error message and an ICE.
>>
>> Pushed as r14-1505-gfae09dfc0e6bf4cfe35d817558827aea78c6426f .
>>
>> Thanks,
>> Harald
>>
> 
> 



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

end of thread, other threads:[~2023-06-03 19:15 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-02 18:05 [PATCH, committed] Fortran: fix diagnostics for SELECT RANK [PR100607] Harald Anlauf
2023-06-03  5:48 ` Paul Richard Thomas
2023-06-03 19:13   ` Harald Anlauf
2023-06-03 19:13     ` Harald Anlauf

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).