From 8a5920d930429f91b269d9265323bf2507a6b8e5 Mon Sep 17 00:00:00 2001 From: Jim MacArthur Date: Thu, 4 Feb 2016 16:59:41 +0000 Subject: [PATCH 06/16] Allow blank format items in format strings This has to be written in a slightly verbose manner because GCC 7 defaults to building with -Werror=implicit-fallthrough which prevents us from just falling through to the default: case. Test written by: Francisco Redondo Marchena Use -fdec-blank-format-item to enable. Also enabled by -fdec. --- gcc/fortran/io.c | 10 ++++++++++ gcc/fortran/lang.opt | 4 ++++ gcc/fortran/options.c | 1 + gcc/testsuite/gfortran.dg/dec_format_empty_item_1.f | 19 +++++++++++++++++++ gcc/testsuite/gfortran.dg/dec_format_empty_item_2.f | 19 +++++++++++++++++++ gcc/testsuite/gfortran.dg/dec_format_empty_item_3.f | 19 +++++++++++++++++++ 6 files changed, 72 insertions(+) create mode 100644 gcc/testsuite/gfortran.dg/dec_format_empty_item_1.f create mode 100644 gcc/testsuite/gfortran.dg/dec_format_empty_item_2.f create mode 100644 gcc/testsuite/gfortran.dg/dec_format_empty_item_3.f diff --git a/gcc/fortran/io.c b/gcc/fortran/io.c index 57117579627..5b355952840 100644 --- a/gcc/fortran/io.c +++ b/gcc/fortran/io.c @@ -756,6 +756,16 @@ format_item_1: error = unexpected_end; goto syntax; + case FMT_RPAREN: + /* Oracle allows a blank format item. */ + if (flag_dec_blank_format_item) + goto finished; + else + { + error = unexpected_element; + goto syntax; + } + default: error = unexpected_element; goto syntax; diff --git a/gcc/fortran/lang.opt b/gcc/fortran/lang.opt index a957b90707f..3d8aaeaaf44 100644 --- a/gcc/fortran/lang.opt +++ b/gcc/fortran/lang.opt @@ -440,6 +440,10 @@ fdec Fortran Var(flag_dec) Enable all DEC language extensions. +fdec-blank-format-item +Fortran Var(flag_dec_blank_format_item) +Enable the use of blank format items in format strings. + fdec-duplicates Fortran Var(flag_dec_duplicates) Allow varibles to be duplicated in the type specification matches. diff --git a/gcc/fortran/options.c b/gcc/fortran/options.c index b652be70f3d..a8c2cf71c3b 100644 --- a/gcc/fortran/options.c +++ b/gcc/fortran/options.c @@ -78,6 +78,7 @@ set_dec_flags (int value) SET_BITFLAG (flag_dec_duplicates, value, value); SET_BITFLAG (flag_dec_char_conversions, value, value); SET_BITFLAG (flag_dec_comparisons, value, value); + SET_BITFLAG (flag_dec_blank_format_item, value, value); } /* Finalize DEC flags. */ diff --git a/gcc/testsuite/gfortran.dg/dec_format_empty_item_1.f b/gcc/testsuite/gfortran.dg/dec_format_empty_item_1.f new file mode 100644 index 00000000000..ed27c18944b --- /dev/null +++ b/gcc/testsuite/gfortran.dg/dec_format_empty_item_1.f @@ -0,0 +1,19 @@ +! { dg-do run } +! { dg-options "-fdec" } +! +! Test blank/empty format items in format string +! +! Test case contributed by Jim MacArthur +! Modified by Mark Eggleston +! + PROGRAM blank_format_items + INTEGER A/0/ + + OPEN(1, status="scratch") + WRITE(1, 10) 100 + REWIND(1) + READ(1, 10) A + IF (a.NE.100) STOP 1 + PRINT 10, A +10 FORMAT( I5,) + END diff --git a/gcc/testsuite/gfortran.dg/dec_format_empty_item_2.f b/gcc/testsuite/gfortran.dg/dec_format_empty_item_2.f new file mode 100644 index 00000000000..2793cb16225 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/dec_format_empty_item_2.f @@ -0,0 +1,19 @@ +! { dg-do run } +! { dg-options "-fdec-blank-format-item" } +! +! Test blank/empty format items in format string +! +! Test case contributed by Jim MacArthur +! Modified by Mark Eggleston +! + PROGRAM blank_format_items + INTEGER A/0/ + + OPEN(1, status="scratch") + WRITE(1, 10) 100 + REWIND(1) + READ(1, 10) A + IF (a.NE.100) STOP 1 + PRINT 10, A +10 FORMAT( I5,) + END diff --git a/gcc/testsuite/gfortran.dg/dec_format_empty_item_3.f b/gcc/testsuite/gfortran.dg/dec_format_empty_item_3.f new file mode 100644 index 00000000000..499db922876 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/dec_format_empty_item_3.f @@ -0,0 +1,19 @@ +! { dg-do compile } +! { dg-options "-fdec -fno-dec-blank-format-item" } +! +! Test blank/empty format items in format string +! +! Test case contributed by Jim MacArthur +! Modified by Mark Eggleston +! + PROGRAM blank_format_items + INTEGER A/0/ + + OPEN(1, status="scratch") + WRITE(1, 10) 100 ! { dg-error "FORMAT label 10 at \\(1\\) not defined" } + REWIND(1) + READ(1, 10) A ! { dg-error "FORMAT label 10 at \\(1\\) not defined" } + IF (a.NE.100) STOP 1 + PRINT 10, A ! { dg-error "FORMAT label 10 at \\(1\\) not defined" } +10 FORMAT( I5,) ! { dg-error "Unexpected element" } + END -- 2.11.0