diff mbox series

[committed] PR fortran/103286 - ICE in resolve_select, at fortran/resolve.c:8848

Message ID trinity-5cfe9ed4-f8e1-484d-a0a9-ac33b4647520-1637093584732@3c-app-gmx-bap58
State New
Headers show
Series [committed] PR fortran/103286 - ICE in resolve_select, at fortran/resolve.c:8848 | expand

Commit Message

Harald Anlauf Nov. 16, 2021, 8:13 p.m. UTC
Committed to mainline as obvious after regtesting.

When issuing an error on an invalid range in a SELECT CASE statement
with a logical case expression, we need to be careful to use the
right locus information.

Thanks,
Harald
diff mbox series

Patch

From 3b3c9932338650c9a402cf1bfbdf7dfc03e185e7 Mon Sep 17 00:00:00 2001
From: Harald Anlauf <anlauf@gmx.de>
Date: Tue, 16 Nov 2021 21:06:06 +0100
Subject: [PATCH] Fortran: avoid NULL pointer dereference on invalid range in
 logical SELECT CASE

gcc/fortran/ChangeLog:

	PR fortran/103286
	* resolve.c (resolve_select): Choose appropriate range limit to
	avoid NULL pointer dereference when generating error message.

gcc/testsuite/ChangeLog:

	PR fortran/103286
	* gfortran.dg/pr103286.f90: New test.
---
 gcc/fortran/resolve.c                  |  3 ++-
 gcc/testsuite/gfortran.dg/pr103286.f90 | 11 +++++++++++
 2 files changed, 13 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gfortran.dg/pr103286.f90

diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c
index 705d2326a29..f074a0ab3a1 100644
--- a/gcc/fortran/resolve.c
+++ b/gcc/fortran/resolve.c
@@ -8846,7 +8846,8 @@  resolve_select (gfc_code *code, bool select_type)
 		  || cp->low != cp->high))
 	    {
 	      gfc_error ("Logical range in CASE statement at %L is not "
-			 "allowed", &cp->low->where);
+			 "allowed",
+			 cp->low ? &cp->low->where : &cp->high->where);
 	      t = false;
 	      break;
 	    }
diff --git a/gcc/testsuite/gfortran.dg/pr103286.f90 b/gcc/testsuite/gfortran.dg/pr103286.f90
new file mode 100644
index 00000000000..1c18b7136ce
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr103286.f90
@@ -0,0 +1,11 @@ 
+! { dg-do compile }
+! { dg-options "std=gnu" }
+! PR fortran/103286 - ICE in resolve_select
+
+program p
+  select case (.true.) ! { dg-warning "Extension: Conversion" }
+  case (1_8)
+  case (:0)            ! { dg-error "Logical range in CASE statement" }
+  case (2:)            ! { dg-error "Logical range in CASE statement" }
+  end select
+end
--
2.26.2