On 11/7/18, Jakub Jelinek <ja...@redhat.com> wrote:
> On Wed, Nov 07, 2018 at 03:07:04PM +0000, Mark Eggleston wrote:
>
>>      PR fortran/87919
>>      * options.c (gfc_handle_option): Removed case OPT_fdec_structure
>>      as it breaks the handling of -fno-dec-structure.
>
> No entries for the tests, i.e.
>       * gfortran.dg/pr87919-dec-structure-1.f: New test.
>       * gfortran.dg/pr87919-dec-structure-2.f: New test.
>       * gfortran.dg/pr87919-dec-structure-3.f: New test.
>       * gfortran.dg/pr87919-dec-structure-4.f: New test.
>
>> diff --git a/gcc/fortran/options.c b/gcc/fortran/options.c
>> index 73f5389361d9..3b7c2d40fe8a 100644
>> --- a/gcc/fortran/options.c
>> +++ b/gcc/fortran/options.c
>> @@ -761,10 +761,6 @@ gfc_handle_option (size_t scode, const char *arg,
>> HOST_WIDE_INT value,
>>        /* Enable all DEC extensions.  */
>>        set_dec_flags (1);
>>        break;
>> -
>> -    case OPT_fdec_structure:
>> -      flag_dec_structure = 1;
>> -      break;
>>      }
>>
>>    Fortran_handle_option_auto (&global_options, &global_options_set,
>
> LGTM, but I'll defer the final review to Fortran maintainers.

Thanks for the patch Mark, I concur with Jakub that it is correct for
what it does. However, I have a few comments in addition to the fixes
recommended by Jakub regarding the test cases.

First, I would prefer to name these test cases as "dec_structure_*.f"
to align with the other (23) -fdec-structure test cases. Second, the
third case (*dec-structure-3.f) is unnecessary because it is identical
in function to dec_structure_1.f90. I concur with the remaining test
cases, as well as Jakub's suggestion to cover "-fdec-structure
-fno-dec-structure" with an additional test. I would name the final
four (= 4 - 1 + 1) tests as "dec_structure_[24-27].f".


I have taken the liberty of extending this patch to cover the
remainder of PR 87919. That is, to fix -fno-* for -fno-dec,
-fno-check-array-temporaries and -fno-init-local-zero. In the extended
patch, the 'value' set for the aforementioned options is no longer
ignored, so that value=1 truly means set and value=0 truly means
"unset". Previously, the aforementioned flags effectively ignored the
value=0 condition. Similarly to the tests Mark provided with
-fdec-structure, I've provided new tests for the various facets of
-fno-dec, -fno-check-array-temporaries, and -fno-init-local-zero.

Below is the changelog. Bootstraps and regtests fine for me on
x86_64-redhat-linux. If it looks OK I'll commit to trunk (and probably
backport to 8-branch and 7-branch since the affected code appears to
be the same for those branches).


>From 2d9e39bbf4a179ae433f33f4e7039b85078ba72f Mon Sep 17 00:00:00 2001
From: Fritz Reese <fritzore...@gmail.com>
Date: Wed, 7 Nov 2018 15:13:50 -0500
Subject: [PATCH] PR fortran/87919

Fix handling -fno-* prefix for init-local-zero, check-array-temporaries and dec.

gcc/fortran/
        * options.c (SET_FLAG, SET_BITFLAG): New macros.
        (set_dec_flags): Unset DEC flags with value==0.
        (set_init_local_zero): New helper for -finit-local-zero flag group.
        (gfc_init_options): Fix disabling of init flags, array temporaries
        check, and dec flags when value is zero (from -fno-*).

gcc/testsuiste/
        * gfortran.dg/array_temporaries_5.f90: New test.
        * gfortran.dg/dec_bitwise_ops_3.f90: Ditto.
        * gfortran.dg/dec_d_lines_3.f: Ditto.
        * gfortran.dg/dec_exp_4.f90: Ditto.
        * gfortran.dg/dec_exp_5.f90: Ditto.
        * gfortran.dg/dec_io_7.f90: Ditto.
        * gfortran.dg/dec_structure_24.f: Ditto.
        * gfortran.dg/dec_structure_25.f: Ditto.
        * gfortran.dg/dec_structure_26.f: Ditto.
        * gfortran.dg/dec_structure_27.f: Ditto.
        * gfortran.dg/dec_type_print_3.f90: Ditto.
        * gfortran.dg/init_flag_20.f90: Ditto.
---
 gcc/fortran/options.c                             | 70 +++++++++++++++--------
 gcc/testsuite/gfortran.dg/array_temporaries_5.f90 | 20 +++++++
 gcc/testsuite/gfortran.dg/dec_bitwise_ops_3.f90   | 19 ++++++
 gcc/testsuite/gfortran.dg/dec_d_lines_3.f         | 10 ++++
 gcc/testsuite/gfortran.dg/dec_exp_4.f90           | 13 +++++
 gcc/testsuite/gfortran.dg/dec_exp_5.f90           | 15 +++++
 gcc/testsuite/gfortran.dg/dec_io_7.f90            | 22 +++++++
 gcc/testsuite/gfortran.dg/dec_structure_24.f      | 21 +++++++
 gcc/testsuite/gfortran.dg/dec_structure_25.f      | 22 +++++++
 gcc/testsuite/gfortran.dg/dec_structure_26.f      | 22 +++++++
 gcc/testsuite/gfortran.dg/dec_structure_27.f      | 20 +++++++
 gcc/testsuite/gfortran.dg/dec_type_print_3.f90    | 29 ++++++++++
 gcc/testsuite/gfortran.dg/init_flag_20.f90        | 62 ++++++++++++++++++++
 13 files changed, 320 insertions(+), 25 deletions(-)
 create mode 100644 gcc/testsuite/gfortran.dg/array_temporaries_5.f90
 create mode 100644 gcc/testsuite/gfortran.dg/dec_bitwise_ops_3.f90
 create mode 100644 gcc/testsuite/gfortran.dg/dec_d_lines_3.f
 create mode 100644 gcc/testsuite/gfortran.dg/dec_exp_4.f90
 create mode 100644 gcc/testsuite/gfortran.dg/dec_exp_5.f90
 create mode 100644 gcc/testsuite/gfortran.dg/dec_io_7.f90
 create mode 100644 gcc/testsuite/gfortran.dg/dec_structure_24.f
 create mode 100644 gcc/testsuite/gfortran.dg/dec_structure_25.f
 create mode 100644 gcc/testsuite/gfortran.dg/dec_structure_26.f
 create mode 100644 gcc/testsuite/gfortran.dg/dec_structure_27.f
 create mode 100644 gcc/testsuite/gfortran.dg/dec_type_print_3.f90
 create mode 100644 gcc/testsuite/gfortran.dg/init_flag_20.f90
From ca3a7bab85b9449adf512fcb29fb1ded6c553598 Mon Sep 17 00:00:00 2001
From: Fritz Reese <fritzoreese@gmail.com>
Date: Wed, 7 Nov 2018 17:02:18 -0500
Subject: [PATCH] PR fortran/87919

Fix handling -fno-* prefix for init-local-zero, check-array-temporaries and dec.

gcc/fortran/
	* options.c (SET_FLAG, SET_BITFLAG): New macros.
	(set_dec_flags): Unset DEC flags with value==0.
	(set_init_local_zero): New helper for -finit-local-zero flag group.
	(gfc_init_options): Fix disabling of init flags, array temporaries
	check, and dec flags when value is zero (from -fno-*).

gcc/testsuiste/
	* gfortran.dg/array_temporaries_5.f90: New test.
	* gfortran.dg/dec_bitwise_ops_3.f90: Ditto.
	* gfortran.dg/dec_d_lines_3.f: Ditto.
	* gfortran.dg/dec_exp_4.f90: Ditto.
	* gfortran.dg/dec_exp_5.f90: Ditto.
	* gfortran.dg/dec_io_7.f90: Ditto.
	* gfortran.dg/dec_structure_24.f: Ditto.
	* gfortran.dg/dec_structure_25.f: Ditto.
	* gfortran.dg/dec_structure_26.f: Ditto.
	* gfortran.dg/dec_structure_27.f: Ditto.
	* gfortran.dg/dec_type_print_3.f90: Ditto.
	* gfortran.dg/init_flag_20.f90: Ditto.
---
 gcc/fortran/options.c                             | 70 +++++++++++++++--------
 gcc/testsuite/gfortran.dg/array_temporaries_5.f90 | 20 +++++++
 gcc/testsuite/gfortran.dg/dec_bitwise_ops_3.f90   | 19 ++++++
 gcc/testsuite/gfortran.dg/dec_d_lines_3.f         | 10 ++++
 gcc/testsuite/gfortran.dg/dec_exp_4.f90           | 13 +++++
 gcc/testsuite/gfortran.dg/dec_exp_5.f90           | 15 +++++
 gcc/testsuite/gfortran.dg/dec_io_7.f90            | 22 +++++++
 gcc/testsuite/gfortran.dg/dec_structure_24.f      | 21 +++++++
 gcc/testsuite/gfortran.dg/dec_structure_25.f      | 22 +++++++
 gcc/testsuite/gfortran.dg/dec_structure_26.f      | 22 +++++++
 gcc/testsuite/gfortran.dg/dec_structure_27.f      | 20 +++++++
 gcc/testsuite/gfortran.dg/dec_type_print_3.f90    | 29 ++++++++++
 gcc/testsuite/gfortran.dg/init_flag_20.f90        | 62 ++++++++++++++++++++
 13 files changed, 320 insertions(+), 25 deletions(-)
 create mode 100644 gcc/testsuite/gfortran.dg/array_temporaries_5.f90
 create mode 100644 gcc/testsuite/gfortran.dg/dec_bitwise_ops_3.f90
 create mode 100644 gcc/testsuite/gfortran.dg/dec_d_lines_3.f
 create mode 100644 gcc/testsuite/gfortran.dg/dec_exp_4.f90
 create mode 100644 gcc/testsuite/gfortran.dg/dec_exp_5.f90
 create mode 100644 gcc/testsuite/gfortran.dg/dec_io_7.f90
 create mode 100644 gcc/testsuite/gfortran.dg/dec_structure_24.f
 create mode 100644 gcc/testsuite/gfortran.dg/dec_structure_25.f
 create mode 100644 gcc/testsuite/gfortran.dg/dec_structure_26.f
 create mode 100644 gcc/testsuite/gfortran.dg/dec_structure_27.f
 create mode 100644 gcc/testsuite/gfortran.dg/dec_type_print_3.f90
 create mode 100644 gcc/testsuite/gfortran.dg/init_flag_20.f90

diff --git a/gcc/fortran/options.c b/gcc/fortran/options.c
index 73f5389361d..e703cad96fd 100644
--- a/gcc/fortran/options.c
+++ b/gcc/fortran/options.c
@@ -32,6 +32,20 @@ along with GCC; see the file COPYING3.  If not see
 
 gfc_option_t gfc_option;
 
+#define _expand(m) m
+
+#define SET_FLAG(flag, condition, on_value, off_value) \
+  do \
+    { \
+      if (condition) \
+	flag = (on_value); \
+      else \
+	flag = (off_value); \
+    } while (0)
+
+#define SET_BITFLAG(flag, condition, value) \
+  _expand (SET_FLAG (flag, condition, (flag | (value)), (flag & ~(value))))
+
 
 /* Set flags that control warnings and errors for different
    Fortran standards to their default values.  Keep in sync with
@@ -47,8 +61,7 @@ set_default_std_flags (void)
   gfc_option.warn_std = GFC_STD_F2018_DEL | GFC_STD_F95_DEL | GFC_STD_LEGACY;
 }
 
-
-/* Set all the DEC extension flags.  */
+/* Set (or unset) the DEC extension flags.  */
 
 static void
 set_dec_flags (int value)
@@ -62,14 +75,30 @@ set_dec_flags (int value)
     }
 
   /* Set other DEC compatibility extensions.  */
-  flag_dollar_ok |= value;
-  flag_cray_pointer |= value;
-  flag_dec_structure |= value;
-  flag_dec_intrinsic_ints |= value;
-  flag_dec_static |= value;
-  flag_dec_math |= value;
+  SET_BITFLAG (flag_dollar_ok, value, value);
+  SET_BITFLAG (flag_cray_pointer, value, value);
+  SET_BITFLAG (flag_dec_structure, value, value);
+  SET_BITFLAG (flag_dec_intrinsic_ints, value, value);
+  SET_BITFLAG (flag_dec_static, value, value);
+  SET_BITFLAG (flag_dec_math, value, value);
 }
 
+/* Enable (or disable) -finit-local-zero.  */
+
+static void
+set_init_local_zero (int value)
+{
+  gfc_option.flag_init_integer_value = 0;
+  gfc_option.flag_init_character_value = (char)0;
+
+  SET_FLAG (gfc_option.flag_init_integer, value, GFC_INIT_INTEGER_ON,
+	    GFC_INIT_INTEGER_OFF);
+  SET_FLAG (gfc_option.flag_init_logical, value, GFC_INIT_LOGICAL_FALSE,
+	    GFC_INIT_LOGICAL_OFF);
+  SET_FLAG (gfc_option.flag_init_character, value, GFC_INIT_CHARACTER_ON,
+	    GFC_INIT_CHARACTER_OFF);
+  SET_FLAG (flag_init_real, value, GFC_INIT_REAL_ZERO, GFC_INIT_REAL_OFF);
+}
 
 /* Return language mask for Fortran options.  */
 
@@ -107,11 +136,7 @@ gfc_init_options (unsigned int decoded_options_count,
 
   gfc_option.flag_preprocessed = 0;
   gfc_option.flag_d_lines = -1;
-  gfc_option.flag_init_integer = GFC_INIT_INTEGER_OFF;
-  gfc_option.flag_init_integer_value = 0;
-  gfc_option.flag_init_logical = GFC_INIT_LOGICAL_OFF;
-  gfc_option.flag_init_character = GFC_INIT_CHARACTER_OFF;
-  gfc_option.flag_init_character_value = (char)0;
+  set_init_local_zero (0);
   
   gfc_option.fpe = 0;
   /* All except GFC_FPE_INEXACT.  */
@@ -604,7 +629,7 @@ gfc_handle_option (size_t scode, const char *arg, HOST_WIDE_INT value,
       break;
 
     case OPT_fcheck_array_temporaries:
-      gfc_option.rtcheck |= GFC_RTCHECK_ARRAY_TEMPS;
+      SET_BITFLAG (gfc_option.rtcheck, value, GFC_RTCHECK_ARRAY_TEMPS);
       break;
       
     case OPT_fd_lines_as_code:
@@ -654,12 +679,7 @@ gfc_handle_option (size_t scode, const char *arg, HOST_WIDE_INT value,
       break;
 
     case OPT_finit_local_zero:
-      gfc_option.flag_init_integer = GFC_INIT_INTEGER_ON;
-      gfc_option.flag_init_integer_value = 0;
-      flag_init_real = GFC_INIT_REAL_ZERO;
-      gfc_option.flag_init_logical = GFC_INIT_LOGICAL_FALSE;
-      gfc_option.flag_init_character = GFC_INIT_CHARACTER_ON;
-      gfc_option.flag_init_character_value = (char)0;
+      set_init_local_zero (value);
       break;
 
     case OPT_finit_logical_:
@@ -759,11 +779,7 @@ gfc_handle_option (size_t scode, const char *arg, HOST_WIDE_INT value,
 
     case OPT_fdec:
       /* Enable all DEC extensions.  */
-      set_dec_flags (1);
-      break;
-
-    case OPT_fdec_structure:
-      flag_dec_structure = 1;
+      set_dec_flags (value);
       break;
     }
 
@@ -855,3 +871,7 @@ gfc_get_option_string (void)
   result[--pos] = '\0';
   return result;
 }
+
+#undef SET_BITFLAG
+#undef SET_FLAG
+#undef _expand
diff --git a/gcc/testsuite/gfortran.dg/array_temporaries_5.f90 b/gcc/testsuite/gfortran.dg/array_temporaries_5.f90
new file mode 100644
index 00000000000..0070a935933
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/array_temporaries_5.f90
@@ -0,0 +1,20 @@
+! { dg-do run }
+! { dg-options "-fcheck-array-temporaries -fno-check-array-temporaries" }
+!
+! PR fortran/87919
+!
+! Ensure -fno-check-array-temporaries disables array temporary checking.
+! Copied from array_temporaries_2.f90.
+!
+
+program test
+  implicit none
+  integer :: a(3,3)
+  call foo(a(:,1))  ! OK, no temporary created
+  call foo(a(1,:))  ! BAD, temporary var created
+contains
+  subroutine foo(x)
+    integer :: x(3)
+    x = 5
+  end subroutine foo
+end program test
diff --git a/gcc/testsuite/gfortran.dg/dec_bitwise_ops_3.f90 b/gcc/testsuite/gfortran.dg/dec_bitwise_ops_3.f90
new file mode 100644
index 00000000000..88887c16f8e
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/dec_bitwise_ops_3.f90
@@ -0,0 +1,19 @@
+! { dg-do compile }
+! { dg-options "-std=legacy -fdec -fno-dec" }
+!
+! Make sure -fno-dec disables bitwise ops and check for the right errors.
+! -std=legacy is added to avoid the .XOR. extension warning.
+!
+
+implicit none
+
+integer i
+
+i = 3  .AND. 5 ! { dg-error "Operands of logical operator" }
+i = 3  .EQV. 5 ! { dg-error "Operands of logical operator" }
+i = 3 .NEQV. 5 ! { dg-error "Operands of logical operator" }
+i =    .NOT. 5 ! { dg-error "Operand of" }
+i = 3   .OR. 5 ! { dg-error "Operands of logical operator" }
+i = 3  .XOR. 5 ! { dg-error "Operands of logical operator" }
+
+end
diff --git a/gcc/testsuite/gfortran.dg/dec_d_lines_3.f b/gcc/testsuite/gfortran.dg/dec_d_lines_3.f
new file mode 100644
index 00000000000..fb35923712b
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/dec_d_lines_3.f
@@ -0,0 +1,10 @@
+! { dg-do compile }
+! { dg-options "-ffixed-form -fno-dec" }
+!
+! Ensure -fd-lines-as-comments is not enabled by default without -fdec.
+!
+
+d     ! { dg-error "Non-numeric character in statement label" }
+D     ! { dg-error "Non-numeric character in statement label" }
+
+      end
diff --git a/gcc/testsuite/gfortran.dg/dec_exp_4.f90 b/gcc/testsuite/gfortran.dg/dec_exp_4.f90
new file mode 100644
index 00000000000..a9c6998d712
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/dec_exp_4.f90
@@ -0,0 +1,13 @@
+! { dg-do compile }
+! { dg-options "-fdec -fno-dec" }
+!
+! Same as dec_exp_2, but make sure -fno-dec disables -fdec.
+!
+
+implicit none
+
+real, parameter :: r1 = 8e ! { dg-error "Missing exponent" }
+real, volatile :: r2
+r2 = 8e ! { dg-error "Missing exponent" }
+
+end
diff --git a/gcc/testsuite/gfortran.dg/dec_exp_5.f90 b/gcc/testsuite/gfortran.dg/dec_exp_5.f90
new file mode 100644
index 00000000000..ce14860418f
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/dec_exp_5.f90
@@ -0,0 +1,15 @@
+! { dg-do run "xfail *-*-*" }
+! { dg-options "-fdec -fno-dec" }
+!
+! Same as dec_exp_3, but make sure -fno-dec disables -fdec.
+!
+
+implicit none
+
+real :: r
+character(2) :: s
+s = '8e'
+
+read (s, *) r ! { XFAIL "Bad real number" }
+
+end
diff --git a/gcc/testsuite/gfortran.dg/dec_io_7.f90 b/gcc/testsuite/gfortran.dg/dec_io_7.f90
new file mode 100644
index 00000000000..339b8896169
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/dec_io_7.f90
@@ -0,0 +1,22 @@
+! { dg-do compile }
+! { dg-options "-fdec -fno-dec" }
+!
+! Make sure -fno-dec rejects -fdec I/O specifiers.
+!
+
+implicit none
+
+integer, parameter :: fd=3
+character(*), parameter :: fname="test.txt"
+
+open (unit=fd, file=fname, readonly) ! { dg-error "is a DEC extension" }
+open (unit=fd, file=fname, action='read', shared) ! { dg-error "is a DEC extension" }
+open (unit=fd, file=fname, action='read', share='DENYNONE') ! { dg-error "is a DEC extension" }
+open (unit=fd, file=fname, action='write', noshared) ! { dg-error "is a DEC extension" }
+open (unit=fd, file=fname, action='write', share='DENYRW') ! { dg-error "is a DEC extension" }
+open(unit=fd,  file=fname, action ='WRITE', carriagecontrol='FORTRAN') ! { dg-error "is a DEC extension" }
+open(unit=fd,  file=fname, action ='WRITE', carriagecontrol='LIST') ! { dg-error "is a DEC extension" }
+open(unit=fd,  file=fname, action ='WRITE', carriagecontrol='NONE') ! { dg-error "is a DEC extension" }
+
+
+end
diff --git a/gcc/testsuite/gfortran.dg/dec_structure_24.f b/gcc/testsuite/gfortran.dg/dec_structure_24.f
new file mode 100644
index 00000000000..410d3af4080
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/dec_structure_24.f
@@ -0,0 +1,21 @@
+! { dg-do compile }
+!
+! PR fortran/87919
+!
+! Should fail to compile without the -fdec or -fdec-structure options.
+!
+! Contributed by Mark Eggleston <mark.eggleston@codethink.com>
+
+      program test
+
+        structure /info/ ! { dg-error "-fdec-structure" }
+          integer a
+          real b
+         end structure   ! { dg-error "END PROGRAM" }
+
+        record /info/ s  ! { dg-error "-fdec-structure" }
+        s.a = 199        ! { dg-error "Unclassifiable" }
+        s.b = 7.6        ! { dg-error "Unclassifiable" }
+        write (*,*) s.a  ! { dg-error "Syntax error in WRITE" }
+        write (*,*) s.b  ! { dg-error "Syntax error in WRITE" }
+      end program test
diff --git a/gcc/testsuite/gfortran.dg/dec_structure_25.f b/gcc/testsuite/gfortran.dg/dec_structure_25.f
new file mode 100644
index 00000000000..4f1ea58b8d0
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/dec_structure_25.f
@@ -0,0 +1,22 @@
+! { dg-do run }
+! { dg-options "-fdec" }
+!
+! PR fortran/87919
+!
+! Should compile and run with the -fdec option.
+!
+! Contributed by Mark Eggleston <mark.eggleston@codethink.com>
+!
+      program test
+
+        structure /info/
+          integer a
+          real b
+         end structure
+
+        record /info/ s
+        s.a = 199
+        s.b = 7.6
+        if (s.a .ne. 199) stop 1
+        if (abs(s.b - 7.6) .gt. 1e-5) stop 2
+      end program test
diff --git a/gcc/testsuite/gfortran.dg/dec_structure_26.f b/gcc/testsuite/gfortran.dg/dec_structure_26.f
new file mode 100644
index 00000000000..186d72f622c
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/dec_structure_26.f
@@ -0,0 +1,22 @@
+! { dg-do compile }
+! { dg-options "-fdec -fno-dec-structure" }
+!
+! PR fortran/87919
+!
+! Should fail to compile with -fdec and -fno-dec-structure.
+!
+! Contributed by Mark Eggleston <mark.eggleston@codethink.com>
+!
+      program test
+
+        structure /info/ ! { dg-error "-fdec-structure" }
+          integer a
+          real b
+         end structure   ! { dg-error "END PROGRAM" }
+
+        record /info/ s  ! { dg-error "-fdec-structure" }
+        s.a = 199        ! { dg-error "Unclassifiable" }
+        s.b = 7.6        ! { dg-error "Unclassifiable" }
+        write (*,*) s.a  ! { dg-error "Syntax error in WRITE" }
+        write (*,*) s.b  ! { dg-error "Syntax error in WRITE" }
+      end program test
diff --git a/gcc/testsuite/gfortran.dg/dec_structure_27.f b/gcc/testsuite/gfortran.dg/dec_structure_27.f
new file mode 100644
index 00000000000..233aa38ab36
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/dec_structure_27.f
@@ -0,0 +1,20 @@
+! { dg-do compile }
+! { dg-options "-fdec-structure -fno-dec-structure" }
+!
+! PR fortran/87919
+!
+! Should fail to compile with -fdec-structure and -fno-dec-structure.
+!
+      program test
+
+        structure /info/ ! { dg-error "-fdec-structure" }
+          integer a
+          real b
+         end structure   ! { dg-error "END PROGRAM" }
+
+        record /info/ s  ! { dg-error "-fdec-structure" }
+        s.a = 199        ! { dg-error "Unclassifiable" }
+        s.b = 7.6        ! { dg-error "Unclassifiable" }
+        write (*,*) s.a  ! { dg-error "Syntax error in WRITE" }
+        write (*,*) s.b  ! { dg-error "Syntax error in WRITE" }
+      end program test
diff --git a/gcc/testsuite/gfortran.dg/dec_type_print_3.f90 b/gcc/testsuite/gfortran.dg/dec_type_print_3.f90
new file mode 100644
index 00000000000..5a9334c8c98
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/dec_type_print_3.f90
@@ -0,0 +1,29 @@
+! { dg-do compile }
+! { dg-options "-fdec -fno-dec" }
+!
+! Ensure that -fno-dec disables the usage of TYPE as an alias for PRINT.
+!
+
+implicit none
+
+integer i /0/, j /1/, k /2/
+character(*), parameter :: fmtstr = "(A11)"
+namelist /nmlist/ i, j, k
+integer, parameter :: n = 5
+
+! Type as alias for print
+type* ! { dg-error "Invalid character in name" }
+type * ! { dg-error "Invalid character in name" }
+type*,'St','ar' ! { dg-error "Invalid character in name" }
+type *, 'St', 'ar' ! { dg-error "Invalid character in name" }
+type 10, 'Integer literal' ! { dg-error "Invalid character in name" }
+type 10, 'Integer variable' ! { dg-error "Invalid character in name" }
+type '(A11)', 'Character literal' ! { dg-error "Invalid character in name" }
+type fmtstr, 'Character variable' ! { dg-error "Unclassifiable statement" }
+type nmlist ! { dg-error "NAMELIST attribute.*?conflicts with PROCEDURE" }
+
+if (n .eq. n) type*, fmtstr ! { dg-error "Cannot assign to a named constant" }
+
+10    format (A11)
+
+end program
diff --git a/gcc/testsuite/gfortran.dg/init_flag_20.f90 b/gcc/testsuite/gfortran.dg/init_flag_20.f90
new file mode 100644
index 00000000000..e05cf951f4c
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/init_flag_20.f90
@@ -0,0 +1,62 @@
+! { dg-do compile }
+! { dg-options "-finit-local-zero -fno-init-local-zero -fdump-tree-original" }
+!
+! PR fortran/87919
+!
+! Make sure -fno-init-local-zero disables -finit-local-zero.
+!
+! The basic test subroutines are copied from init_flag_1.f90, but this test
+! only compiles and check the original tree. The conditional checks are only
+! kept to prevent the variables from being marked unused.
+!
+
+subroutine real_test
+  real r1
+  real r2(10)
+  dimension r3(10,10)
+  if (r1 /= 0.0) STOP 1
+  if (r2(2) /= 0.0) STOP 2
+  if (r3(5,5) /= 0.0) STOP 3
+  if (r4 /= 0.0) STOP 4
+end subroutine real_test
+
+subroutine logical_test
+  logical l1
+  logical l2(2)
+  if (l1 .neqv. .false.) STOP 5
+  if (l2(2) .neqv. .false.) STOP 6
+end subroutine logical_test
+
+subroutine int_test
+  integer i1
+  integer i2(10)
+  dimension i3(10,10)
+  if (i1 /= 0) STOP 7
+  if (i2(2) /= 0) STOP 8
+  if (i3(5,5) /= 0) STOP 9
+  if (i4 /= 0) STOP 10
+end subroutine int_test
+
+subroutine complex_test
+  complex c1
+  complex c2(20,20)
+  if (c1 /= (0.0,0.0)) STOP 11
+  if (c2(1,1) /= (0.0,0.0)) STOP 12
+end subroutine complex_test
+
+subroutine char_test
+  character*1 c1
+  character*8 c2, c3(5)
+  character c4(10)
+  if (c1 /= '\0') STOP 13
+  if (c2 /= '\0\0\0\0\0\0\0\0') STOP 14
+  if (c3(1) /= '\0\0\0\0\0\0\0\0') STOP 15
+  if (c3(5) /= '\0\0\0\0\0\0\0\0') STOP 16
+  if (c4(5) /= '\0') STOP 17
+end subroutine char_test
+
+! Make sure no initialization code is generated.
+! { dg-final { scan-tree-dump-times "r\[1-4] *= *\[0\{]" 0 "original" } }
+! { dg-final { scan-tree-dump-times "l\[12] *= *\[0\{]" 0 "original" } }
+! { dg-final { scan-tree-dump-times "i\[1-4] *= *\[0\{]" 0 "original" } }
+! { dg-final { scan-tree-dump-times "memmove *\[(]\[^,]*c\[1-4]" 0 "original" } }
-- 
2.12.2

Reply via email to