aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
Diffstat (limited to 'gcc')
-rw-r--r--gcc/fortran/ChangeLog5
-rw-r--r--gcc/fortran/gfortran.texi21
-rw-r--r--gcc/fortran/primary.c17
-rw-r--r--gcc/testsuite/ChangeLog6
-rw-r--r--gcc/testsuite/gfortran.dg/dec_loc_rval_1.f9019
-rw-r--r--gcc/testsuite/gfortran.dg/dec_loc_rval_2.f9014
-rw-r--r--gcc/testsuite/gfortran.dg/dec_loc_rval_3.f0313
7 files changed, 92 insertions, 3 deletions
diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog
index 986eedf..9bd1d80 100644
--- a/gcc/fortran/ChangeLog
+++ b/gcc/fortran/ChangeLog
@@ -1,5 +1,10 @@
2016-10-25 Fritz Reese <fritzoreese@gmail.com>
+ * primary.c (gfc_match_rvalue): Match %LOC as LOC with -std=legacy.
+ * gfortran.texi: Document.
+
+2016-10-25 Fritz Reese <fritzoreese@gmail.com>
+
* decl.c (gfc_match_type): New function.
* match.h (gfc_match_type): New function.
* match.c (gfc_match_if): Special case for one-line IFs.
diff --git a/gcc/fortran/gfortran.texi b/gcc/fortran/gfortran.texi
index fb47c13..e1256bd 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 3803b88..bcbaeaa 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 a64e74d..33a9913 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,5 +1,11 @@
2016-10-25 Fritz Reese <fritzoreese@gmail.com>
+ * 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 <fritzoreese@gmail.com>
+
* gfortran.dg/dec_type_print.f90: New testcase.
2016-10-25 Fritz Reese <fritzoreese@gmail.com>
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 0000000..070b8db
--- /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 0000000..20eeb85
--- /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 0000000..b3441b8
--- /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