public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* [patch. fortran] PR102595 ICE in var_element, at fortran/decl.c
@ 2023-01-21  1:46 Jerry D
  2023-01-21  5:16 ` Jerry D
  0 siblings, 1 reply; 4+ messages in thread
From: Jerry D @ 2023-01-21  1:46 UTC (permalink / raw)
  To: gfortran; +Cc: gcc-patches

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

A PARAMETER value is not allowed in a DATA statement, similar to an 
EQUIVALENCE.

The check for this was in gfc_assign_data_value() in data.cc which turns 
out to be too late when trying to assign a zero sized array.

To correct this, the check is moved to match_variable() in primary.cc 
where  a similar check for EQUIVALENCE is already being performed.

Regression tested on x86_64-linux-gnu.  I will create a test case from 
the case presented in the PR which is trivial.  There are already two 
other tests in the test suite that exercise this check.

OK for trunk?

Regards,

Jerry

[-- Attachment #2: pr102595.diff --]
[-- Type: text/x-patch, Size: 1189 bytes --]

diff --git a/gcc/fortran/data.cc b/gcc/fortran/data.cc
index 443d35da9cf..d29eb12c1b1 100644
--- a/gcc/fortran/data.cc
+++ b/gcc/fortran/data.cc
@@ -244,13 +244,6 @@ gfc_assign_data_value (gfc_expr *lvalue, gfc_expr *rvalue, mpz_t index,
 		    "array-element nor a scalar-structure-component";
 
   symbol = lvalue->symtree->n.sym;
-  if (symbol->attr.flavor == FL_PARAMETER)
-    {
-      gfc_error ("PARAMETER %qs shall not appear in a DATA statement at %L",
-		 symbol->name, &lvalue->where);
-      return false;
-    }
-
   init = symbol->value;
   last_ts = &symbol->ts;
   last_con = NULL;
diff --git a/gcc/fortran/primary.cc b/gcc/fortran/primary.cc
index 543d9cc0de4..158f039f225 100644
--- a/gcc/fortran/primary.cc
+++ b/gcc/fortran/primary.cc
@@ -4076,6 +4076,11 @@ match_variable (gfc_expr **result, int equiv_flag, int host_flag)
 	  gfc_error ("Named constant at %C in an EQUIVALENCE");
 	  return MATCH_ERROR;
 	}
+      if (gfc_in_match_data())
+	{
+	  gfc_error ("PARAMETER %qs shall not appear in a DATA statement at %C",
+		      sym->name);
+	}
       /* Otherwise this is checked for and an error given in the
 	 variable definition context checks.  */
       break;

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

* Re: [patch. fortran] PR102595 ICE in var_element, at fortran/decl.c
  2023-01-21  1:46 [patch. fortran] PR102595 ICE in var_element, at fortran/decl.c Jerry D
@ 2023-01-21  5:16 ` Jerry D
  2023-01-21 18:27   ` Jerry D
  0 siblings, 1 reply; 4+ messages in thread
From: Jerry D @ 2023-01-21  5:16 UTC (permalink / raw)
  To: gfortran; +Cc: gcc-patches

On 1/20/23 5:46 PM, Jerry D wrote:
> A PARAMETER value is not allowed in a DATA statement, similar to an 
> EQUIVALENCE.
> 
> The check for this was in gfc_assign_data_value() in data.cc which turns 
> out to be too late when trying to assign a zero sized array.

Correction, the chunk in data.cc must remain for one test case. I 
spotted this after rerunning check-fortran for several variations.

Regards,

Jerry

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

* Re: [patch. fortran] PR102595 ICE in var_element, at fortran/decl.c
  2023-01-21  5:16 ` Jerry D
@ 2023-01-21 18:27   ` Jerry D
  2023-01-21 19:14     ` Harald Anlauf
  0 siblings, 1 reply; 4+ messages in thread
From: Jerry D @ 2023-01-21 18:27 UTC (permalink / raw)
  To: gfortran; +Cc: gcc-patches

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

On 1/20/23 9:16 PM, Jerry D wrote:
> On 1/20/23 5:46 PM, Jerry D wrote:
>> A PARAMETER value is not allowed in a DATA statement, similar to an 
>> EQUIVALENCE.
>>
>> The check for this was in gfc_assign_data_value() in data.cc which 
>> turns out to be too late when trying to assign a zero sized array.
> 
> Correction, the chunk in data.cc must remain for one test case. I 
> spotted this after rerunning check-fortran for several variations.
> 

Attached patch is revised to include a new test case and adjustment of 
an existing test case.  It also adds in a return MATCH_ERROR I 
accidentally left of the first submit when I was cleaning some things up.

Ok for Mainline?

Jeyy

[-- Attachment #2: pr102595b.diff --]
[-- Type: text/x-patch, Size: 2256 bytes --]

diff --git a/gcc/fortran/data.cc b/gcc/fortran/data.cc
index 443d35da9cf..d29eb12c1b1 100644
--- a/gcc/fortran/data.cc
+++ b/gcc/fortran/data.cc
@@ -244,13 +244,6 @@ gfc_assign_data_value (gfc_expr *lvalue, gfc_expr *rvalue, mpz_t index,
 		    "array-element nor a scalar-structure-component";
 
   symbol = lvalue->symtree->n.sym;
-  if (symbol->attr.flavor == FL_PARAMETER)
-    {
-      gfc_error ("PARAMETER %qs shall not appear in a DATA statement at %L",
-		 symbol->name, &lvalue->where);
-      return false;
-    }
-
   init = symbol->value;
   last_ts = &symbol->ts;
   last_con = NULL;
diff --git a/gcc/fortran/primary.cc b/gcc/fortran/primary.cc
index 543d9cc0de4..28ce5fea865 100644
--- a/gcc/fortran/primary.cc
+++ b/gcc/fortran/primary.cc
@@ -4076,8 +4076,14 @@ match_variable (gfc_expr **result, int equiv_flag, int host_flag)
 	  gfc_error ("Named constant at %C in an EQUIVALENCE");
 	  return MATCH_ERROR;
 	}
-      /* Otherwise this is checked for and an error given in the
-	 variable definition context checks.  */
+      if (gfc_in_match_data())
+	{
+	  gfc_error ("PARAMETER %qs shall not appear in a DATA statement at %C",
+		      sym->name);
+	  return MATCH_ERROR;
+	}
+	/* Otherwise this is checked for an error given in the
+	   variable definition context checks.  */
       break;
 
     case FL_PROCEDURE:
diff --git a/gcc/testsuite/gfortran.dg/parameter_data0.f90 b/gcc/testsuite/gfortran.dg/parameter_data0.f90
new file mode 100644
index 00000000000..4f1da9ea42e
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/parameter_data0.f90
@@ -0,0 +1,6 @@
+! { dg-do compile }
+! PR fortran/102595  Similar to 88048 with a zero sized array
+program p
+   complex, parameter:: x(0) = 2
+   data x%im /3.0/ ! { dg-error "shall not appear in a DATA statement" }
+end
diff --git a/gcc/testsuite/gfortran.dg/pr88048.f90 b/gcc/testsuite/gfortran.dg/pr88048.f90
index 11293934330..ad82d45881c 100644
--- a/gcc/testsuite/gfortran.dg/pr88048.f90
+++ b/gcc/testsuite/gfortran.dg/pr88048.f90
@@ -2,6 +2,6 @@
 ! PR fortran/88048
 program p
    integer, parameter :: a(2) = 1
-   data a(2) /a(1)/                 ! { dg-error "definable entity" }
+   data a(2) /a(1)/  ! { dg-error "shall not appear in a DATA statement" }
    print *, a
 end

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

* Re: [patch. fortran] PR102595 ICE in var_element, at fortran/decl.c
  2023-01-21 18:27   ` Jerry D
@ 2023-01-21 19:14     ` Harald Anlauf
  0 siblings, 0 replies; 4+ messages in thread
From: Harald Anlauf @ 2023-01-21 19:14 UTC (permalink / raw)
  To: Jerry D, gfortran; +Cc: gcc-patches

Hi Jerry,

Am 21.01.23 um 19:27 schrieb Jerry D via Gcc-patches:
> On 1/20/23 9:16 PM, Jerry D wrote:
>> On 1/20/23 5:46 PM, Jerry D wrote:
>>> A PARAMETER value is not allowed in a DATA statement, similar to an
>>> EQUIVALENCE.
>>>
>>> The check for this was in gfc_assign_data_value() in data.cc which
>>> turns out to be too late when trying to assign a zero sized array.
>>
>> Correction, the chunk in data.cc must remain for one test case. I
>> spotted this after rerunning check-fortran for several variations.
>>
>
> Attached patch is revised to include a new test case and adjustment of
> an existing test case.  It also adds in a return MATCH_ERROR I
> accidentally left of the first submit when I was cleaning some things up.
>
> Ok for Mainline?

the patch looks good to me, so ok for mainline.
But please provide a commit message next time.

Thanks,
Harald

>
> Jeyy


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

end of thread, other threads:[~2023-01-21 19:14 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-21  1:46 [patch. fortran] PR102595 ICE in var_element, at fortran/decl.c Jerry D
2023-01-21  5:16 ` Jerry D
2023-01-21 18:27   ` Jerry D
2023-01-21 19:14     ` 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).