public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] PR fortran/68244 -- Check for NULL() in an array spec.
@ 2015-11-07 20:20 Steve Kargl
  2015-11-08  8:58 ` Paul Richard Thomas
  0 siblings, 1 reply; 2+ messages in thread
From: Steve Kargl @ 2015-11-07 20:20 UTC (permalink / raw)
  To: fortran, gcc-patches

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

NULL() can only appear in a few situations.  It cannot
be part of an array spec.  See testcase for example.
OK to commit?

2015-11-07  Steven G. Kargl  <kargl@gc.gnu.org>

	PR fortran/68224
	* array.c (match_array_element_spec): Check of invalid NULL().
	While here, fix nearby comments.

2015-11-07  Steven G. Kargl  <kargl@gc.gnu.org>

	PR fortran/68224
	* gfortran.dg/pr68224.f90: New test.

-- 
Steve

[-- Attachment #2: pr68224.diff --]
[-- Type: text/x-diff, Size: 2728 bytes --]

Index: gcc/fortran/array.c
===================================================================
--- gcc/fortran/array.c	(revision 229933)
+++ gcc/fortran/array.c	(working copy)
@@ -147,9 +147,9 @@ matched:
 }
 
 
-/* Match an array reference, whether it is the whole array or a
-   particular elements or a section. If init is set, the reference has
-   to consist of init expressions.  */
+/* Match an array reference, whether it is the whole array or particular
+   elements or a section.  If init is set, the reference has to consist
+   of init expressions.  */
 
 match
 gfc_match_array_ref (gfc_array_ref *ar, gfc_array_spec *as, int init,
@@ -422,6 +422,13 @@ match_array_element_spec (gfc_array_spec
   if (!gfc_expr_check_typed (*upper, gfc_current_ns, false))
     return AS_UNKNOWN;
 
+  if ((*upper)->expr_type == EXPR_FUNCTION && (*upper)->ts.type == BT_UNKNOWN
+      && (*upper)->symtree && strcmp ((*upper)->symtree->name, "null") == 0)
+    {
+      gfc_error ("Expecting a scalar INTEGER expression at %C");
+      return AS_UNKNOWN;
+    }
+
   if (gfc_match_char (':') == MATCH_NO)
     {
       *lower = gfc_get_int_expr (gfc_default_integer_kind, NULL, 1);
@@ -442,13 +449,20 @@ match_array_element_spec (gfc_array_spec
   if (!gfc_expr_check_typed (*upper, gfc_current_ns, false))
     return AS_UNKNOWN;
 
+  if ((*upper)->expr_type == EXPR_FUNCTION && (*upper)->ts.type == BT_UNKNOWN
+      && (*upper)->symtree && strcmp ((*upper)->symtree->name, "null") == 0)
+    {
+      gfc_error ("Expecting a scalar INTEGER expression at %C");
+      return AS_UNKNOWN;
+    }
+
   return AS_EXPLICIT;
 }
 
 
 /* Matches an array specification, incidentally figuring out what sort
-   it is. Match either a normal array specification, or a coarray spec
-   or both. Optionally allow [:] for coarrays.  */
+   it is.  Match either a normal array specification, or a coarray spec
+   or both.  Optionally allow [:] for coarrays.  */
 
 match
 gfc_match_array_spec (gfc_array_spec **asp, bool match_dim, bool match_codim)
Index: gcc/testsuite/gfortran.dg/pr68224.f90
===================================================================
--- gcc/testsuite/gfortran.dg/pr68224.f90	(revision 0)
+++ gcc/testsuite/gfortran.dg/pr68224.f90	(working copy)
@@ -0,0 +1,10 @@
+! { dg-do compile }
+! PR fortran/68224
+! Original code contribute by Gerhard Steinmetz
+! <gerhard dot steinmetz dot fortran at t-online dot de>
+! 
+program p
+   integer, parameter :: a(null()) = [1, 2]   ! { dg-error "scalar INTEGER expression" }
+   integer, parameter :: b(null():*) = [1, 2]   ! { dg-error "scalar INTEGER expression" }
+   integer, parameter :: c(1:null()) = [1, 2]   ! { dg-error "scalar INTEGER expression" }
+end program p

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

* Re: [PATCH] PR fortran/68244 -- Check for NULL() in an array spec.
  2015-11-07 20:20 [PATCH] PR fortran/68244 -- Check for NULL() in an array spec Steve Kargl
@ 2015-11-08  8:58 ` Paul Richard Thomas
  0 siblings, 0 replies; 2+ messages in thread
From: Paul Richard Thomas @ 2015-11-08  8:58 UTC (permalink / raw)
  To: Steve Kargl; +Cc: fortran, gcc-patches

Hi Steve,

That's OK for trunk.

Thanks for the patch.

Paul

On 7 November 2015 at 21:20, Steve Kargl
<sgk@troutmask.apl.washington.edu> wrote:
> NULL() can only appear in a few situations.  It cannot
> be part of an array spec.  See testcase for example.
> OK to commit?
>
> 2015-11-07  Steven G. Kargl  <kargl@gc.gnu.org>
>
>         PR fortran/68224
>         * array.c (match_array_element_spec): Check of invalid NULL().
>         While here, fix nearby comments.
>
> 2015-11-07  Steven G. Kargl  <kargl@gc.gnu.org>
>
>         PR fortran/68224
>         * gfortran.dg/pr68224.f90: New test.
>
> --
> Steve



-- 
Outside of a dog, a book is a man's best friend. Inside of a dog it's
too dark to read.

Groucho Marx

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

end of thread, other threads:[~2015-11-08  8:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-07 20:20 [PATCH] PR fortran/68244 -- Check for NULL() in an array spec Steve Kargl
2015-11-08  8:58 ` Paul Richard Thomas

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