The attached patch adresses part of an issue raised in PR fortran/63514 by enforcing F2008:C1282 and F2018:C1588. Regression tested on x86_64-*-freebsd. OK to commit?
PS: the actual underlying point of PR fortran/63514 is bogus, and I recommend that it be closed with WONTFIX. 2018-06-08 Steven G. Kargl <ka...@gcc.gnu.org> PR fortran/63514 * symbol.c (gfc_add_volatile): Enforce F2008:C1282 and F2018:C1588. 2018-06-08 Steven G. Kargl <ka...@gcc.gnu.org> PR fortran/63514 * gfortran.dg/pr63514.f90: New test. -- Steve
Index: gcc/fortran/symbol.c =================================================================== --- gcc/fortran/symbol.c (revision 261285) +++ gcc/fortran/symbol.c (working copy) @@ -1349,6 +1349,20 @@ gfc_add_volatile (symbol_attribute *attr, const char * where)) return false; + /* F2008: C1282 A designator of a variable with the VOLATILE attribute + shall not appear in a pure subprogram. + + F2018: C1588 A local variable of a pure subprogram, or of a BLOCK + construct within a pure subprogram, shall not have the SAVE or + VOLATILE attribute. */ + if (gfc_pure (NULL)) + { + gfc_error ("VOLATILE attribute at %L cannot be specified in a " + "PURE procedure", where); + return false; + } + + attr->volatile_ = 1; attr->volatile_ns = gfc_current_ns; return check_conflict (attr, name, where); Index: gcc/testsuite/gfortran.dg/pr63514.f90 =================================================================== --- gcc/testsuite/gfortran.dg/pr63514.f90 (nonexistent) +++ gcc/testsuite/gfortran.dg/pr63514.f90 (working copy) @@ -0,0 +1,41 @@ +! { dg-do compile } +! PR fortran/63514.f90 +program foo + + implicit none + + integer, volatile :: n + + n = 0 + + call bar + call bah + + contains + + subroutine bar + integer k + integer, volatile :: m + block + integer, save :: i + integer, volatile :: j + i = 42 + j = 2 * i + k = i + j + n + end block + end subroutine bar + + pure subroutine bah + integer k + integer, volatile :: m ! { dg-error "cannot be specified in a PURE" } + block + integer, save :: i ! { dg-error "cannot be specified in a PURE" } + integer, volatile :: j ! { dg-error "cannot be specified in a PURE" } + i = 42 ! { dg-error "has no IMPLICIT type" } + j = 2 * i ! { dg-error "has no IMPLICIT type" } + k = i + j + n + end block + m = k * m ! { dg-error "has no IMPLICIT type" } + end subroutine bah + +end program foo