Hi all,

The attached patch eliminates several warnings by adjusting which enumerator is used in the subject offending code. I fixed this by adding an enumerator at the end of the file_mode definition. This then triggered a warning in several other places for an unhandled case in the switch statements. I cleared those by throwing in an assert (false) since it cant happen unless something really goes wrong somehow.

Regardless, regression tested on x86_64-pc-linux-gnu.

OK for trunk? No applicable test case.

Jerry

2019-09-22  Jerry DeLisle  <jvdeli...@gcc.gnu.org>

        PR libfortran/91593
        * io/transfer.c (file_mode, current_mode,
        formatted_transfer_scalar_read, formatted_transfer_scalar_write,
        pre_position, next_record_r, next_record_w): Add and use
        FORMATTED_UNSPECIFIED to enumeration.

PS

While I was at it, I 'touched' all files in libgfortran/io to see what other warnings are left, There is another odd warning I have not sorted out yet.

../../../trunk/libgfortran/io/read.c: In function ‘read_decimal’:
../../../trunk/libgfortran/io/read.c:641:9: warning: comparison of integer expressions of different signedness: ‘size_t’ {aka ‘long unsigned int’} and ‘int’ [-Wsign-compare]
  641 |   if (w == DEFAULT_WIDTH)
      |         ^~
In function ‘btoa_big’,
    inlined from ‘write_b’ at ../../../trunk/libgfortran/io/write.c:1212:11:
../../../trunk/libgfortran/io/write.c:1051:6: warning: writing 1 byte into a region of size 0 [-Wstringop-overflow=]
 1051 |   *q = '\0';
      |   ~~~^~~~~~

The first of these two I understand. The second one about region of size 0 puzzles me.
diff --git a/libgfortran/io/transfer.c b/libgfortran/io/transfer.c
index c43360f6332..3ba72a47d3e 100644
--- a/libgfortran/io/transfer.c
+++ b/libgfortran/io/transfer.c
@@ -32,6 +32,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #include "format.h"
 #include "unix.h"
 #include "async.h"
+#include <assert.h>
 #include <string.h>
 #include <errno.h>
 
@@ -193,7 +194,8 @@ static const st_option async_opt[] = {
 
 typedef enum
 { FORMATTED_SEQUENTIAL, UNFORMATTED_SEQUENTIAL,
-  FORMATTED_DIRECT, UNFORMATTED_DIRECT, FORMATTED_STREAM, UNFORMATTED_STREAM
+  FORMATTED_DIRECT, UNFORMATTED_DIRECT, FORMATTED_STREAM,
+  UNFORMATTED_STREAM, FORMATTED_UNSPECIFIED
 }
 file_mode;
 
@@ -203,7 +205,7 @@ current_mode (st_parameter_dt *dtp)
 {
   file_mode m;
 
-  m = FORM_UNSPECIFIED;
+  m = FORMATTED_UNSPECIFIED;
 
   if (dtp->u.p.current_unit->flags.access == ACCESS_DIRECT)
     {
@@ -1727,17 +1729,17 @@ formatted_transfer_scalar_read (st_parameter_dt *dtp, bt type, void *p, int kind
 
 	case FMT_S:
 	  consume_data_flag = 0;
-	  dtp->u.p.sign_status = SIGN_S;
+	  dtp->u.p.sign_status = SIGN_PROCDEFINED;
 	  break;
 
 	case FMT_SS:
 	  consume_data_flag = 0;
-	  dtp->u.p.sign_status = SIGN_SS;
+	  dtp->u.p.sign_status = SIGN_SUPPRESS;
 	  break;
 
 	case FMT_SP:
 	  consume_data_flag = 0;
-	  dtp->u.p.sign_status = SIGN_SP;
+	  dtp->u.p.sign_status = SIGN_PLUS;
 	  break;
 
 	case FMT_BN:
@@ -2186,17 +2188,17 @@ formatted_transfer_scalar_write (st_parameter_dt *dtp, bt type, void *p, int kin
 
 	case FMT_S:
 	  consume_data_flag = 0;
-	  dtp->u.p.sign_status = SIGN_S;
+	  dtp->u.p.sign_status = SIGN_PROCDEFINED;
 	  break;
 
 	case FMT_SS:
 	  consume_data_flag = 0;
-	  dtp->u.p.sign_status = SIGN_SS;
+	  dtp->u.p.sign_status = SIGN_SUPPRESS;
 	  break;
 
 	case FMT_SP:
 	  consume_data_flag = 0;
-	  dtp->u.p.sign_status = SIGN_SP;
+	  dtp->u.p.sign_status = SIGN_PLUS;
 	  break;
 
 	case FMT_BN:
@@ -2766,6 +2768,8 @@ pre_position (st_parameter_dt *dtp)
     case UNFORMATTED_DIRECT:
       dtp->u.p.current_unit->bytes_left = dtp->u.p.current_unit->recl;
       break;
+    case FORMATTED_UNSPECIFIED:
+      assert (false); /* Should never happen.  */
     }
 
   dtp->u.p.current_unit->current_record = 1;
@@ -3637,6 +3641,8 @@ next_record_r (st_parameter_dt *dtp, int done)
 	  while (p != '\n');
 	}
       break;
+    case FORMATTED_UNSPECIFIED:
+      assert (false); /* Should never happen.  */
     }
 }
 
@@ -4002,6 +4008,8 @@ next_record_w (st_parameter_dt *dtp, int done)
 	}
 
       break;
+    case FORMATTED_UNSPECIFIED:
+      assert (false); /* Should never happen.  */
 
     io_error:
       generate_error (&dtp->common, LIBERROR_OS, NULL);

Reply via email to