From 598dc594fa743db13fae4a884e33079a06de07e2 Mon Sep 17 00:00:00 2001 From: "Steven G. Kargl" Date: Sat, 9 Jun 2018 15:33:28 +0000 Subject: [PATCH] re PR fortran/63514 (functions containing volatile are considered pure) 2018-06-09 Steven G. Kargl PR fortran/63514 * symbol.c (gfc_add_volatile): Enforce F2008:C1282 and F2018:C1588. 2018-06-09 Steven G. Kargl PR fortran/63514 * gfortran.dg/pr63514.f90: New test. From-SVN: r261360 --- gcc/fortran/ChangeLog | 5 ++++ gcc/fortran/symbol.c | 14 +++++++++ gcc/testsuite/ChangeLog | 5 ++++ gcc/testsuite/gfortran.dg/pr63514.f90 | 41 +++++++++++++++++++++++++++ 4 files changed, 65 insertions(+) create mode 100644 gcc/testsuite/gfortran.dg/pr63514.f90 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index dbda6ef58d6..5f1ed3bc75d 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,8 @@ +2018-06-09 Steven G. Kargl + + PR fortran/63514 + * symbol.c (gfc_add_volatile): Enforce F2008:C1282 and F2018:C1588. + 2018-06-08 Thomas Koenig PR fortran/85631 diff --git a/gcc/fortran/symbol.c b/gcc/fortran/symbol.c index 4f060633da1..b4a950aa4af 100644 --- a/gcc/fortran/symbol.c +++ b/gcc/fortran/symbol.c @@ -1349,6 +1349,20 @@ gfc_add_volatile (symbol_attribute *attr, const char *name, locus *where) 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); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 8b9b37f1970..36135a88521 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-06-09 Steven G. Kargl + + PR fortran/63514 + * gfortran.dg/pr63514.f90: New test. + 2018-06-08 Thomas Koenig PR fortran/85631 diff --git a/gcc/testsuite/gfortran.dg/pr63514.f90 b/gcc/testsuite/gfortran.dg/pr63514.f90 new file mode 100644 index 00000000000..389fb92608e --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr63514.f90 @@ -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 -- 2.30.2