re PR fortran/50960 ([OOP] vtables not marked as constant)
authorTobias Burnus <burnus@net-b.de>
Thu, 3 Nov 2011 22:32:37 +0000 (23:32 +0100)
committerTobias Burnus <burnus@gcc.gnu.org>
Thu, 3 Nov 2011 22:32:37 +0000 (23:32 +0100)
2011-11-03  Tobias Burnus  <burnus@net-b.de>

        PR fortran/50960
        * trans-decl.c (gfc_finish_var_decl): Mark PARAMETER as
        * TREE_READONLY.

2011-11-03  Tobias Burnus  <burnus@net-b.de>

        PR fortran/50960
        * gfortran.dg/module_parameter_array_refs_2.f90: New.

From-SVN: r180878

gcc/fortran/ChangeLog
gcc/fortran/trans-decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/module_parameter_array_refs_2.f90 [new file with mode: 0644]

index 802c2ff..f29eab0 100644 (file)
@@ -1,3 +1,8 @@
+2011-11-03  Tobias Burnus  <burnus@net-b.de>
+
+       PR fortran/50960
+       * trans-decl.c (gfc_finish_var_decl): Mark PARAMETER as TREE_READONLY.
+
 2011-11-03  Mikael Morin  <mikael@gcc.gnu.org>
 
        * trans.h (struct gfc_ss, struct gfc_ss_info): Move field
index b7460b7..b90b0ab 100644 (file)
@@ -517,6 +517,10 @@ gfc_finish_var_decl (tree decl, gfc_symbol * sym)
   /* If it wasn't used we wouldn't be getting it.  */
   TREE_USED (decl) = 1;
 
+  if (sym->attr.flavor == FL_PARAMETER
+      && (sym->attr.dimension || sym->ts.type == BT_DERIVED))
+    TREE_READONLY (decl) = 1;
+
   /* Chain this decl to the pending declarations.  Don't do pushdecl()
      because this would add them to the current scope rather than the
      function scope.  */
index 986bc70..d561072 100644 (file)
@@ -1,3 +1,8 @@
+2011-11-03  Tobias Burnus  <burnus@net-b.de>
+
+       PR fortran/50960
+       * gfortran.dg/module_parameter_array_refs_2.f90: New.
+
 2011-11-03  Richard Guenther  <rguenther@suse.de>
 
        PR middle-end/50079
diff --git a/gcc/testsuite/gfortran.dg/module_parameter_array_refs_2.f90 b/gcc/testsuite/gfortran.dg/module_parameter_array_refs_2.f90
new file mode 100644 (file)
index 0000000..385761d
--- /dev/null
@@ -0,0 +1,23 @@
+! { dg-do compile }
+! { dg-options "-O" }
+! { dg-final { scan-assembler-not "i_am_optimized_away" } }
+!
+! PR fortran/50960
+!
+! PARAMETER arrays and derived types exists as static variables.
+! Check that the their read-only nature is taken into account
+! when optimizations are done.
+!
+
+module m
+  integer, parameter :: PARA(*) = [1,2,3,4,5,6,7,8,9,10]
+end module m
+
+subroutine test()
+use m
+integer :: i
+i = 1
+if (para(i) /= 1) call i_am_optimized_away()
+end
+
+! { dg-final { cleanup-modules "m" } }