From: Fritz Reese Date: Tue, 25 Oct 2016 15:27:39 +0000 (+0000) Subject: Enable %LOC as an rvalue with -std=legacy. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=cd714e1e56c53aeda0fe365a1daebf217731b42a;p=gcc.git Enable %LOC as an rvalue with -std=legacy. gcc/fortran/ * primary.c (gfc_match_rvalue): Match %LOC as LOC with -std=legacy. * gfortran.texi: Document. gcc/testsuite/gfortran.dg/ * dec_loc_rval_1.f90: New test. * dec_loc_rval_2.f90: New test. * dec_loc_rval_3.f90: New test. From-SVN: r241519 --- diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 986eedfde2a..9bd1d805d59 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,8 @@ +2016-10-25 Fritz Reese + + * primary.c (gfc_match_rvalue): Match %LOC as LOC with -std=legacy. + * gfortran.texi: Document. + 2016-10-25 Fritz Reese * decl.c (gfc_match_type): New function. diff --git a/gcc/fortran/gfortran.texi b/gcc/fortran/gfortran.texi index fb47c13ceaa..e1256bd8824 100644 --- a/gcc/fortran/gfortran.texi +++ b/gcc/fortran/gfortran.texi @@ -1467,6 +1467,7 @@ compatibility extensions along with those enabled by @option{-std=legacy}. * Extended math intrinsics:: * Form feed as whitespace:: * TYPE as an alias for PRINT:: +* %LOC as an rvalue:: @end menu @node Old-style kind specifications @@ -2537,6 +2538,26 @@ TYPE *, 'hello world' PRINT *, 'hello world' @end smallexample +@node %LOC as an rvalue +@subsection %LOC as an rvalue +@cindex LOC +Normally @code{%LOC} is allowed only in parameter lists. However the intrinsic +function @code{LOC} does the same thing, and is usable as the right-hand-side of +assignments. For compatibility, GNU Fortran supports the use of @code{%LOC} as +an alias for the builtin @code{LOC} with @option{-std=legacy}. With this +feature enabled the following two examples are equivalent: + +@smallexample +integer :: i, l +l = %loc(i) +call sub(l) +@end smallexample + +@smallexample +integer :: i +call sub(%loc(i)) +@end smallexample + @node Extensions not implemented in GNU Fortran @section Extensions not implemented in GNU Fortran diff --git a/gcc/fortran/primary.c b/gcc/fortran/primary.c index 3803b889354..bcbaeaa6369 100644 --- a/gcc/fortran/primary.c +++ b/gcc/fortran/primary.c @@ -2971,9 +2971,20 @@ gfc_match_rvalue (gfc_expr **result) bool implicit_char; gfc_ref *ref; - m = gfc_match_name (name); - if (m != MATCH_YES) - return m; + m = gfc_match ("%%loc"); + if (m == MATCH_YES) + { + if (!gfc_notify_std (GFC_STD_LEGACY, "%%LOC() as an rvalue at %C")) + return MATCH_ERROR; + strncpy (name, "loc", 4); + } + + else + { + m = gfc_match_name (name); + if (m != MATCH_YES) + return m; + } /* Check if the symbol exists. */ if (gfc_find_sym_tree (name, NULL, 1, &symtree)) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index a64e74d91d9..33a99136e59 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2016-10-25 Fritz Reese + + * gfortran.dg/dec_loc_rval_1.f90: New test. + * gfortran.dg/dec_loc_rval_2.f90: New test. + * gfortran.dg/dec_loc_rval_3.f90: New test. + 2016-10-25 Fritz Reese * gfortran.dg/dec_type_print.f90: New testcase. diff --git a/gcc/testsuite/gfortran.dg/dec_loc_rval_1.f90 b/gcc/testsuite/gfortran.dg/dec_loc_rval_1.f90 new file mode 100644 index 00000000000..070b8db1c08 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/dec_loc_rval_1.f90 @@ -0,0 +1,19 @@ +! { dg-do run } +! { dg-options "-std=legacy" } +! +! Test the usage of %loc as an rvalue. +! +program main +implicit none + +integer :: i, j, k + +i = loc(j) +k = %loc(j) + +if (i .ne. k) then + print *, "bad %loc value" + call abort() +endif + +end diff --git a/gcc/testsuite/gfortran.dg/dec_loc_rval_2.f90 b/gcc/testsuite/gfortran.dg/dec_loc_rval_2.f90 new file mode 100644 index 00000000000..20eeb854e92 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/dec_loc_rval_2.f90 @@ -0,0 +1,14 @@ +! { dg-do compile } +! { dg-options "-std=gnu" } +! +! Test warnings for usage of %loc as an rvalue without -std=legacy. +! +program main +implicit none + +integer, volatile :: i, j, k + +i = loc(j) +k = %loc(j) ! { dg-warning "Legacy Extension:" } + +end diff --git a/gcc/testsuite/gfortran.dg/dec_loc_rval_3.f03 b/gcc/testsuite/gfortran.dg/dec_loc_rval_3.f03 new file mode 100644 index 00000000000..b3441b806ef --- /dev/null +++ b/gcc/testsuite/gfortran.dg/dec_loc_rval_3.f03 @@ -0,0 +1,13 @@ +! { dg-do compile } +! { dg-options "-std=f2003" } +! +! Test errors for usage of %loc as an rvalue with a real standard. +! +program main +implicit none + +integer, volatile :: i, j, k + +k = %loc(j) ! { dg-error "Legacy Extension:" } + +end