[patch, fortran] Implement VOLATILE statement/attribute (PR 29601)

Tobias Burnus burnus@net-b.de
Tue Oct 31 02:49:00 GMT 2006


:ADDPATCH:

Hello,

the following patch implements the volatile attribute and statement.
I'm not positive that this patch does the right thing (especially
whether it indeeds sets the right attribute [e.g. also for pointers]).

For the restrictions I use:
C526  If the VOLATILE attribute is specified, the PARAMETER, INTRINSIC,
EXTERNAL, or INTENT(IN) attribute shall not be specified.
(In principle VALUE is missing, but I think it is not yet supported by
gfortran.)
Whether it should prohibit other objects, I don't know. (I wonder about
e.g. about pure functions.)

I use
  TREE_THIS_VOLATILE (decl) = 1
(this automatically sets TREE_SIDE_EFFECTS according to tree.h)

Using the fortran program:
------------------
  real :: l,m
  real, volatile :: r = 3.
  volatile :: l
  l = 4.0
  m = 3.0
------------------
the dumped original tree  is:
------------------
MAIN__ ()
{
  real4 m;
  real4 l;
  _gfortran_set_std (70, 127, 0);
  l = 4.0e+0;
  m = 3.0e+0;
}
------------------

Whereas using the C program
------------------
int main() {
  volatile int r;
  r = 5.0;
}
------------------
the tree contains
------------------
{
  volatile int r;
    volatile int r;
  r = 5;
}
------------------

This puzzles me. Glancing at Andy's g95 source code showed that he uses
also only TREE_THIS_VOLATILE().

My C program might be using the following function - or not as I think
the "r" is not static.
varasm.c: /* Make the rtl for variable VAR be volatile. Use this only
for static variables. */
make_var_volatile (tree var) {
  gcc_assert (MEM_P (DECL_RTL (var)));
  MEM_VOLATILE_P (DECL_RTL (var)) = 1;
}

 * * *

The test cases only shows that volatiles is correctly recognized (F2003)
or rejected (F95), but I don't know how to test that the variable is
actually marked as volatile.


Regtested on x86_64-unknown-linux-gnu.

Tobias


fortran/
2006-10-30  Tobias Burnus  <burnus@net-b.de>

    fortran/29601
    * symbol.c (check_conflict, gfc_add_volatile): Add volatile support.
    * decl.c (match_attr_spec, gfc_match_volatile): Add volatile support.
    * gfortran.h (symbol_attribute): Add volatile_ to struct.
    * resolve.c (was_declared): Add volatile support.
    * trans-decl.c (gfc_finish_var_decl): Add volatile support.
    * match.h: Declare gfc_match_volatile.
    * parse.c (decode_statement): Recognize volatile.


testsuite/
2006-10-30  Tobias Burnus  <burnus@net-b.de>

    fortran/29601
    * volatile.f90: Add.
    * volatile2.f90: Add.
    * volatile3.f90: Add.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: volatile.diff
Type: text/x-patch
Size: 10934 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20061031/3ff1b3a8/attachment.bin>


More information about the Fortran mailing list