https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63514

            Bug ID: 63514
           Summary: functions containing volatile are considered pure
           Product: gcc
           Version: 5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: Joost.VandeVondele at mat dot ethz.ch

The following testcase is miscompiled at -O1:

> cat test.f90
MODULE M1
CONTAINS
  INTEGER FUNCTION F1()
    INTEGER, VOLATILE :: i
    F1=i
  END FUNCTION
  INTEGER FUNCTION F2()
    F2=F1()+F1()
  END FUNCTION
END MODULE

> gfortran -O1 -fdump-tree-optimized -fno-inline -c test.f90

;; Function f2 (__m1_MOD_f2, funcdef_no=0, decl_uid=2355, cgraph_uid=0,
symbol_order=0)

f2 ()
{
  integer(kind=4) __var_1;
  integer(kind=4) __result_f2.0_3;

  <bb 2>:
  __var_1_2 = f1 ();
  __result_f2.0_3 = __var_1_2 + __var_1_2;
  return __result_f2.0_3;

}

f1 should be called twice in this case, as it returns the value of a volatile.
I believe f1 is being considered as pure here, which seems not correct.
Actually, it doesn't generate an error if I add 'PURE' to the function
definition, which I assume is not correct either.

Reply via email to