]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR fortran/63514 (functions containing volatile are considered pure)
authorSteven G. Kargl <kargl@gcc.gnu.org>
Sat, 9 Jun 2018 20:10:34 +0000 (20:10 +0000)
committerSteven G. Kargl <kargl@gcc.gnu.org>
Sat, 9 Jun 2018 20:10:34 +0000 (20:10 +0000)
2018-06-09  Steven G. Kargl  <kargl@gcc.gnu.org>

PR fortran/63514
* symbol.c (gfc_add_volatile): Enforce F2008:C1282 and F2018:C1588.

2018-06-09  Steven G. Kargl  <kargl@gcc.gnu.org>

PR fortran/63514
* gfortran.dg/pr63514.f90: New test.

From-SVN: r261375

gcc/fortran/ChangeLog
gcc/fortran/symbol.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/pr63514.f90 [new file with mode: 0644]

index d1355c85bba56eb1f94b6454ad444d4ddedbf06f..b3ca3ff0eb7f6e169ab9dd301b3f7c328b1f69fb 100644 (file)
@@ -1,3 +1,8 @@
+2018-06-09  Steven G. Kargl  <kargl@gcc.gnu.org>
+
+       PR fortran/63514
+       * symbol.c (gfc_add_volatile): Enforce F2008:C1282 and F2018:C1588.
+
 2018-06-09  Steven G. Kargl  <kargl@gcc.gnu.org>
 
        PR fortran/78278
index ec43e635bf3688f52b3bc21498f4995b9f1ecb59..6917b22dff28c3c5fc7141c7d9136e0e0620c634 100644 (file)
@@ -1259,6 +1259,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);
index 0751cf324116d9fd525cfbdb67730d68edbe1f75..da5ffdd1e54682245d6d1fad07c8ebe492e3450b 100644 (file)
@@ -1,3 +1,8 @@
+2018-06-09  Steven G. Kargl  <kargl@gcc.gnu.org>
+
+       PR fortran/63514
+       * gfortran.dg/pr63514.f90: New test.
+
 2018-06-09  Steven G. Kargl  <kargl@gcc.gnu.org>
 
        PR fortran/78278
diff --git a/gcc/testsuite/gfortran.dg/pr63514.f90 b/gcc/testsuite/gfortran.dg/pr63514.f90
new file mode 100644 (file)
index 0000000..389fb92
--- /dev/null
@@ -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