PR fortran/119199
gcc/fortran/ChangeLog:
* decl.cc (gfc_match_save): Reject SAVE statement of a COMMON block
when in a BLOCK construct.
* trans-common.cc (translate_common): Avoid NULL pointer dereference.
gcc/testsuite/ChangeLog:
* gfortran.dg/common_30.f90: New test.
* gfortran.dg/common_31.f90: New test.
if (m == MATCH_NO)
goto syntax;
+ /* F2023:C1108: A SAVE statement in a BLOCK construct shall contain a
+ saved-entity-list that does not specify a common-block-name. */
+ if (gfc_current_state () == COMP_BLOCK)
+ {
+ gfc_error ("SAVE of COMMON block %qs at %C is not allowed "
+ "in a BLOCK construct", n);
+ return MATCH_ERROR;
+ }
+
c = gfc_get_common (n, 0);
c->saved = 1;
align = 1;
saw_equiv = false;
- if (var_list->attr.omp_allocate)
+ if (var_list && var_list->attr.omp_allocate)
gfc_error ("Sorry, !$OMP allocate for COMMON block variable %qs at %L "
"not supported", common->name, &common->where);
--- /dev/null
+! { dg-do compile }
+! PR fortran/119199
+!
+! One cannot SAVE an undefined COMMON block
+!
+! Contributed by David Binderman
+
+program main
+ save /argmnt1/ ! { dg-error "does not exist" }
+end
--- /dev/null
+! { dg-do compile }
+! PR fortran/119199 - reject SAVE of a COMMON in a BLOCK construct
+!
+! F2023:C1108: A SAVE statement in a BLOCK construct shall contain a
+! saved-entity-list that does not specify a common-block-name.
+!
+! Contributed by David Binderman
+
+program main
+ real r
+ common /argmnt2/ r
+ block
+ save /argmnt2/ ! { dg-error "not allowed in a BLOCK construct" }
+ end block
+end