diff mbox

[Fortran] Four small DEC extensions

Message ID CAE4aFAnpFYm+hrmG+w_VGMBZP001kxiL-SGAmOKuNDDd6ToaSQ@mail.gmail.com
State New
Headers show

Commit Message

Fritz Reese Oct. 24, 2016, 2:23 p.m. UTC
https://gcc.gnu.org/ml/fortran/2016-10/msg00087.html et. al.
> On 12/10/16 13:30, Fritz Reese wrote:
>> Here I submit for review four small extensions to the GNU Fortran
>> frontend for compatibility with legacy code. I figure it might be a
>> nice change of pace from my larger patches. Never fear, for I have
>> more large patches to come, which I will continue to submit
>> one-at-a-time.

Sorry I took a break from this last week. Back on it this week. I
really hope I can get the rest of my major extensions in before the
next release stage, which is apparently imminent, so I might have an
overwhelming number of submissions this week...

Here's how I'm thinking of the flags situation: we use -std=legacy for
old compatibility stuff that users shouldn't use, and -fdec for
ancient compatibility stuff that users _really_ shouldn't use. So if a
user wants the compiler to mimic an old DEC compiler they hit -fdec
and get -std=legacy and all the bells and whistles of the
deleted/obsolete/compatibility extensions without question. Otherwise
they can just use -std=legacy for a more reasonable compilation, or
-std=gnu for some such extensions with reasonable warnings.

Anyway, here's a resubmission of the several patches for the four
extensions mentioned previously, plus an initial cleanup patch for
-fdec. Sorry to pork-barrel the cleanup patch in here, but it combines
some stuff I've been meaning to touch up with the change of making
-fdec into flag_dec using Fortran Var. (This is necessary for the
type-print and future extensions to be enabled with -fdec without
their own flag.)

To summarize, we have
0001 Cleanup -fdec: rolls some options in with fdec that were
documented as being a part of it previously (-fdollar-ok,
-fcray-pointer, -fd-lines-as-comments, legacy/deleted/obsolete feature
standard bits) and moves fdec-structure out of gfc_option to use
Fortran Var.
0002 [always] Form feed: feed characters ('\f') accepted as whitespace in source
0003 [-fdec] TYPE is an alias for PRINT
0004 [-std=legacy] %LOC() can be used as an rval (like the LOC() intrinsic)
0005 [-std=legacy] Support for .XOR. operator (same as .NEQV.)

The -std=legacy extensions of course compile clean with -std=legacy,
give warnings with-std=gnu, and give errors with -std=f*.

OK for trunk now? (regtests x86_64-redhat-linux)

---
Fritz Reese

==> 0001-Cleanup-fdec.patch <==
From e2563d592af111c7f67ea7f3e41cf6b83d294b1e Mon Sep 17 00:00:00 2001
From: Fritz Reese <fritzoreese@gmail.com>
Date: Mon, 24 Oct 2016 09:56:11 -0400
Subject: [PATCH 1/5] Cleanup -fdec.

        gcc/fortran/
        * invoke.texi, gfortran.texi: Touch up documentation of -fdec.
        * gfortran.h (gfc_option): Move flag_dec_structure out of gfc_option.
        * decl.c (match_record_decl, gfc_match_decl_type_spec,
        gfc_match_structure_decl): Ditto.
        * match.c (gfc_match_member_sep): Ditto.
        * options.c (gfc_handle_option): Ditto.
        * lang.opt (fdec-structure): Use Fortran Var for flag_dec_structure.
        * lang.opt (fdec): Use Fortran Var to create flag_dec.
        * options.c (set_dec_flags): With -fdec enable -fcray-pointer,
        -fd-lines-as-comments (default), and legacy/deleted/obsolete standards.

==> 0002-Treat-form-feed-as-whitespace.patch <==
From d771dd0e49c30498b6dbd94e1edc3689b5a5cab3 Mon Sep 17 00:00:00 2001
From: Fritz Reese <fritzoreese@gmail.com>
Date: Mon, 17 Oct 2016 08:44:27 -0400
Subject: [PATCH 2/5] Treat form feed as whitespace.

        gcc/fortran/
        * gfortran.texi: Document.
        * gfortran.h (gfc_is_whitespace): Include form feed ('\f').

        gcc/testsuite/gfortran.dg/
        * feed_1.f90, feed_2.f90: New testcases.

==> 0003-Support-TYPE-as-alias-for-PRINT-with-fdec.patch <==
From 3a26fbde4ace44b3565872f84c2f2dfcec813cb8 Mon Sep 17 00:00:00 2001
From: Fritz Reese <fritzoreese@gmail.com>
Date: Mon, 24 Oct 2016 09:56:53 -0400
Subject: [PATCH 3/5] Support TYPE as alias for PRINT with -fdec.

        gcc/fortran/
        * 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.
        * gfortran.texi: Update documentation.
        * parse.c (decode_statement): Invoke gfc_match_type.

        gcc/testsuite/gfortran.dg/
        * dec_type_print.f90: New testcase.

==> 0004-Enable-LOC-as-an-rvalue-with-std-legacy.patch <==
From 965d3a0f3dfd4597ce5c1108bb75141e95dd1fbc Mon Sep 17 00:00:00 2001
From: Fritz Reese <fritzoreese@gmail.com>
Date: Mon, 24 Oct 2016 09:46:58 -0400
Subject: [PATCH 4/5] 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, dec_loc_rval_2.f90, dec_loc_rval_3.f90: New.

==> 0005-Enable-.XOR.-operator-with-std-legacy.patch <==
From 72f1ffbd6d7d277b212aa5265b439c87a644cb55 Mon Sep 17 00:00:00 2001
From: Fritz Reese <fritzoreese@gmail.com>
Date: Mon, 24 Oct 2016 09:50:22 -0400
Subject: [PATCH 5/5] Enable .XOR. operator with -std=legacy.

        gcc/fortran/
        * gfortran.texi: Document.
        * match.c (gfc_match_intrinsic_op): Match ".XOR." with -std=legacy.

        gcc/testsuite/gfortran.dg/
        * dec_logical_xor_1.f90, dec_logical_xor_2.f90, dec_logical_xor_3.f90:
        New testsuites.

Comments

Jerry DeLisle Oct. 25, 2016, 2:47 a.m. UTC | #1
On 10/24/2016 07:23 AM, Fritz Reese wrote:
> https://gcc.gnu.org/ml/fortran/2016-10/msg00087.html et. al.
>> On 12/10/16 13:30, Fritz Reese wrote:
>>> Here I submit for review four small extensions to the GNU Fortran
>>> frontend for compatibility with legacy code. I figure it might be a
>>> nice change of pace from my larger patches. Never fear, for I have
>>> more large patches to come, which I will continue to submit
>>> one-at-a-time.
>
> Sorry I took a break from this last week. Back on it this week. I
> really hope I can get the rest of my major extensions in before the
> next release stage, which is apparently imminent, so I might have an
> overwhelming number of submissions this week...
>
> Here's how I'm thinking of the flags situation: we use -std=legacy for
> old compatibility stuff that users shouldn't use, and -fdec for
> ancient compatibility stuff that users _really_ shouldn't use. So if a
> user wants the compiler to mimic an old DEC compiler they hit -fdec
> and get -std=legacy and all the bells and whistles of the
> deleted/obsolete/compatibility extensions without question. Otherwise
> they can just use -std=legacy for a more reasonable compilation, or
> -std=gnu for some such extensions with reasonable warnings.
>
> Anyway, here's a resubmission of the several patches for the four
> extensions mentioned previously, plus an initial cleanup patch for
> -fdec. Sorry to pork-barrel the cleanup patch in here, but it combines
> some stuff I've been meaning to touch up with the change of making
> -fdec into flag_dec using Fortran Var. (This is necessary for the
> type-print and future extensions to be enabled with -fdec without
> their own flag.)
>
> To summarize, we have
> 0001 Cleanup -fdec: rolls some options in with fdec that were
> documented as being a part of it previously (-fdollar-ok,
> -fcray-pointer, -fd-lines-as-comments, legacy/deleted/obsolete feature
> standard bits) and moves fdec-structure out of gfc_option to use
> Fortran Var.
> 0002 [always] Form feed: feed characters ('\f') accepted as whitespace in source
> 0003 [-fdec] TYPE is an alias for PRINT
> 0004 [-std=legacy] %LOC() can be used as an rval (like the LOC() intrinsic)
> 0005 [-std=legacy] Support for .XOR. operator (same as .NEQV.)
>
> The -std=legacy extensions of course compile clean with -std=legacy,
> give warnings with-std=gnu, and give errors with -std=f*.
>
> OK for trunk now? (regtests x86_64-redhat-linux)
>

God do go!

Jerry
Fritz Reese Oct. 25, 2016, 3:46 p.m. UTC | #2
On Mon, Oct 24, 2016 at 10:47 PM, Jerry DeLisle <jvdelisle@charter.net> wrote:
> On 10/24/2016 07:23 AM, Fritz Reese wrote:
>>
>> https://gcc.gnu.org/ml/fortran/2016-10/msg00087.html et. al.
>>>
>>> On 12/10/16 13:30, Fritz Reese wrote:
>>>>
>>>> Here I submit for review four small extensions to the GNU Fortran
>>>> frontend for compatibility with legacy code. I figure it might be a
>>>> nice change of pace from my larger patches. Never fear, for I have
>>>> more large patches to come, which I will continue to submit
>>>> one-at-a-time.
...
>> OK for trunk now? (regtests x86_64-redhat-linux)
>>
>
> God do go!
>
> Jerry
>

Committed r241516, r241517, r241518, r241519.

---
Fritz Reese
---
Fritz Reese


On Mon, Oct 24, 2016 at 10:47 PM, Jerry DeLisle <jvdelisle@charter.net> wrote:
> On 10/24/2016 07:23 AM, Fritz Reese wrote:
>>
>> https://gcc.gnu.org/ml/fortran/2016-10/msg00087.html et. al.
>>>
>>> On 12/10/16 13:30, Fritz Reese wrote:
>>>>
>>>> Here I submit for review four small extensions to the GNU Fortran
>>>> frontend for compatibility with legacy code. I figure it might be a
>>>> nice change of pace from my larger patches. Never fear, for I have
>>>> more large patches to come, which I will continue to submit
>>>> one-at-a-time.
>>
>>
>> Sorry I took a break from this last week. Back on it this week. I
>> really hope I can get the rest of my major extensions in before the
>> next release stage, which is apparently imminent, so I might have an
>> overwhelming number of submissions this week...
>>
>> Here's how I'm thinking of the flags situation: we use -std=legacy for
>> old compatibility stuff that users shouldn't use, and -fdec for
>> ancient compatibility stuff that users _really_ shouldn't use. So if a
>> user wants the compiler to mimic an old DEC compiler they hit -fdec
>> and get -std=legacy and all the bells and whistles of the
>> deleted/obsolete/compatibility extensions without question. Otherwise
>> they can just use -std=legacy for a more reasonable compilation, or
>> -std=gnu for some such extensions with reasonable warnings.
>>
>> Anyway, here's a resubmission of the several patches for the four
>> extensions mentioned previously, plus an initial cleanup patch for
>> -fdec. Sorry to pork-barrel the cleanup patch in here, but it combines
>> some stuff I've been meaning to touch up with the change of making
>> -fdec into flag_dec using Fortran Var. (This is necessary for the
>> type-print and future extensions to be enabled with -fdec without
>> their own flag.)
>>
>> To summarize, we have
>> 0001 Cleanup -fdec: rolls some options in with fdec that were
>> documented as being a part of it previously (-fdollar-ok,
>> -fcray-pointer, -fd-lines-as-comments, legacy/deleted/obsolete feature
>> standard bits) and moves fdec-structure out of gfc_option to use
>> Fortran Var.
>> 0002 [always] Form feed: feed characters ('\f') accepted as whitespace in
>> source
>> 0003 [-fdec] TYPE is an alias for PRINT
>> 0004 [-std=legacy] %LOC() can be used as an rval (like the LOC()
>> intrinsic)
>> 0005 [-std=legacy] Support for .XOR. operator (same as .NEQV.)
>>
>> The -std=legacy extensions of course compile clean with -std=legacy,
>> give warnings with-std=gnu, and give errors with -std=f*.
>>
>> OK for trunk now? (regtests x86_64-redhat-linux)
>>
>
> God do go!
>
> Jerry
>
Fritz Reese Oct. 25, 2016, 3:48 p.m. UTC | #3
On Tue, Oct 25, 2016 at 11:46 AM, Fritz Reese <fritzoreese@gmail.com> wrote:
...
> Committed r241516, r241517, r241518, r241519.

... and r241520.

---
Fritz Reese
diff mbox

Patch

diff --git a/gcc/fortran/gfortran.texi b/gcc/fortran/gfortran.texi
index e1256bd..60b619f 100644
--- a/gcc/fortran/gfortran.texi
+++ b/gcc/fortran/gfortran.texi
@@ -1468,6 +1468,7 @@  compatibility extensions along with those enabled by @option{-std=legacy}.
 * Form feed as whitespace::
 * TYPE as an alias for PRINT::
 * %LOC as an rvalue::
+* .XOR. operator::
 @end menu
 
 @node Old-style kind specifications
@@ -2558,6 +2559,14 @@  integer :: i
 call sub(%loc(i))
 @end smallexample
 
+@node .XOR. operator
+@subsection .XOR. operator
+@cindex operators, xor
+
+GNU Fortran supports @code{.XOR.} as a logical operator with @code{-std=legacy}
+for compatibility with legacy code. @code{.XOR.} is equivalent to
+@code{.NEQV.}. That is, the output is true if and only if the inputs differ.
+
 
 @node Extensions not implemented in GNU Fortran
 @section Extensions not implemented in GNU Fortran
@@ -2582,7 +2591,6 @@  code that uses them running with the GNU Fortran compiler.
 * Variable FORMAT expressions::
 @c * Q edit descriptor::
 @c * TYPE and ACCEPT I/O Statements::
-@c * .XOR. operator::
 @c * CARRIAGECONTROL, DEFAULTFILE, DISPOSE and RECORDTYPE I/O specifiers::
 @c * Omitted arguments in procedure call::
 * Alternate complex function syntax::
diff --git a/gcc/fortran/match.c b/gcc/fortran/match.c
index 046028e..21af734 100644
--- a/gcc/fortran/match.c
+++ b/gcc/fortran/match.c
@@ -960,6 +960,19 @@  gfc_match_intrinsic_op (gfc_intrinsic_op *result)
 	    }
 	  break;
 
+	case 'x':
+	  if (gfc_next_ascii_char () == 'o'
+	      && gfc_next_ascii_char () == 'r'
+	      && gfc_next_ascii_char () == '.')
+	    {
+              if (!gfc_notify_std (GFC_STD_LEGACY, ".XOR. operator at %C"))
+                return MATCH_ERROR;
+	      /* Matched ".xor." - equivalent to ".neqv.".  */
+	      *result = INTRINSIC_NEQV;
+	      return MATCH_YES;
+	    }
+	  break;
+
 	default:
 	  break;
 	}
diff --git a/gcc/testsuite/gfortran.dg/dec_logical_xor_1.f90 b/gcc/testsuite/gfortran.dg/dec_logical_xor_1.f90
new file mode 100644
index 0000000..d10fa19
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/dec_logical_xor_1.f90
@@ -0,0 +1,40 @@ 
+! { dg-do run }
+! { dg-options "-std=legacy" }
+!
+! Test logical .XOR. operator.
+!
+
+implicit none
+
+logical :: in1, in2, neqv_out, lxor_out, truth_table(2)
+integer :: i, j, ixor_out, ieor_out
+
+truth_table(1) = .true.
+truth_table(2) = .false.
+do i = 1,2
+  do j = 1,2
+    in1 = truth_table(j)
+    in2 = truth_table(i)
+
+    ! make sure logical xor works
+    neqv_out = in1 .neqv. in2
+    lxor_out = in1 .xor. in2
+
+    if ( neqv_out .neqv. lxor_out ) then
+      print *, "(",in1,in2,") .neqv.: ",neqv_out,"  .xor.: ",lxor_out
+      call abort()
+    endif
+
+    ! make sure we didn't break xor() intrinsic
+    ixor_out = xor(i*7, j*5)
+    ieor_out = ieor(i*7, j*5)
+
+    if ( ixor_out .ne. ieor_out ) then
+      print *, "(",in1,in2,") ieor(): ",ieor_out,"  xor(): ",ixor_out
+      call abort()
+    endif
+
+  enddo
+enddo
+
+end
diff --git a/gcc/testsuite/gfortran.dg/dec_logical_xor_2.f90 b/gcc/testsuite/gfortran.dg/dec_logical_xor_2.f90
new file mode 100644
index 0000000..4e43179
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/dec_logical_xor_2.f90
@@ -0,0 +1,12 @@ 
+! { dg-do compile }
+! { dg-options "-std=gnu" }
+!
+! Test warnings for logical .XOR. operator without -std=legacy.
+!
+
+implicit none
+
+logical, volatile :: in1, in2, xor_out
+xor_out = in1 .xor. in2 ! { dg-warning ".XOR. operator" }
+
+end
diff --git a/gcc/testsuite/gfortran.dg/dec_logical_xor_3.f03 b/gcc/testsuite/gfortran.dg/dec_logical_xor_3.f03
new file mode 100644
index 0000000..ff029fc
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/dec_logical_xor_3.f03
@@ -0,0 +1,12 @@ 
+! { dg-do compile }
+! { dg-options "-std=f2003" }
+!
+! Test errors for logical .XOR. operator with a real standard.
+!
+
+implicit none
+
+logical, volatile :: in1, in2, xor_out
+xor_out = in1 .xor. in2 ! { dg-error ".XOR. operator" }
+
+end
-- 
1.7.1