[Bug fortran/83191] [7/8 Regression] Writing a namelist with repeated complex numbers
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83191 Jerry DeLisle changed: What|Removed |Added Status|ASSIGNED|RESOLVED Resolution|--- |FIXED --- Comment #8 from Jerry DeLisle --- Fixed on trunk and on 7. Closing
[Bug fortran/83191] [7/8 Regression] Writing a namelist with repeated complex numbers
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83191 --- Comment #7 from Jerry DeLisle --- Author: jvdelisle Date: Sun Dec 3 20:43:59 2017 New Revision: 255368 URL: https://gcc.gnu.org/viewcvs?rev=255368=gcc=rev Log: 2017-12-03 Jerry DeLisleDominique d'Humieres Backport from trunk PR libgfortran/83191 * io/transfer.c (list_formatted_read_scalar): Do not set namelist_mode bit here. (namelist_read): Likewise. (data_transfer_init): Clear the mode bit here. (finalize_transfer): Do set the mode bit just before any calls to namelist_read or namelist_write. It can now be referred to in complex_write. * io/write.c (write_complex): Suppress the leading blanks when namelist_mode bit is not set to 1. * gfortran.dg/namelist_95.f90: New test. Added: branches/gcc-7-branch/gcc/testsuite/gfortran.dg/namelist_95.f90 Modified: branches/gcc-7-branch/gcc/testsuite/ChangeLog branches/gcc-7-branch/libgfortran/ChangeLog branches/gcc-7-branch/libgfortran/io/list_read.c branches/gcc-7-branch/libgfortran/io/transfer.c branches/gcc-7-branch/libgfortran/io/write.c
[Bug fortran/83191] [7/8 Regression] Writing a namelist with repeated complex numbers
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83191 --- Comment #6 from Jerry DeLisle --- Author: jvdelisle Date: Sun Dec 3 16:47:12 2017 New Revision: 255365 URL: https://gcc.gnu.org/viewcvs?rev=255365=gcc=rev Log: 2017-12-03 Jerry DeLisleDominique d'Humieres PR libgfortran/83191 * io/transfer.c (list_formatted_read_scalar): Do not set namelist_mode bit here. (namelist_read): Likewise. (data_transfer_init): Clear the mode bit here. (finalize_transfer): Do set the mode bit just before any calls to namelist_read or namelist_write. It can now be referred to in complex_write. ^ io/write.c (write_complex): Suppress the leading blanks when namelist_mode bit is not set to 1. * gfortran.dg/namelist_95.f90: New test. Added: trunk/gcc/testsuite/gfortran.dg/namelist_95.f90 Modified: trunk/gcc/testsuite/ChangeLog trunk/libgfortran/ChangeLog trunk/libgfortran/io/list_read.c trunk/libgfortran/io/transfer.c trunk/libgfortran/io/write.c
[Bug fortran/83191] [7/8 Regression] Writing a namelist with repeated complex numbers
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83191 --- Comment #5 from Jerry DeLisle --- (In reply to Jerry DeLisle from comment #4) > Alternatively one could do this: > > @@ -1809,9 +1809,11 @@ write_complex (st_parameter_dt *dtp, const char > *source, int kind, size_t size) > precision, buf_size, result1, _len1); >get_float_string (dtp, , source + size / 2 , kind, 0, buffer, > precision, buf_size, result2, _len2); > - lblanks = width - res_len1 - res_len2 - 3; > - > - write_x (dtp, lblanks, lblanks); > + if (!dtp->u.p.namelist_mode) > +{ > + lblanks = width - res_len1 - res_len2 - 3; > + write_x (dtp, lblanks, lblanks); > +} >write_char (dtp, '('); >write_float_string (dtp, result1, res_len1); >write_char (dtp, semi_comma); With the following tweak: @@ -1950,6 +1952,7 @@ list_formatted_write (st_parameter_dt *dtp, bt type, void *p, int kind, size * GFC_SIZE_OF_CHAR_KIND(kind) : size; tmp = (char *) p; + dtp->u.p.namelist_mode = 0; /* Big loop over all the elements. */ for (elem = 0; elem < nelems; elem++) @@ -2394,6 +2397,7 @@ namelist_write (st_parameter_dt *dtp) char c; char *dummy_name = NULL; + dtp->u.p.namelist_mode = 1; /* Set the delimiter for namelist output. */ switch (dtp->u.p.current_unit->delim_status) {
[Bug fortran/83191] [7/8 Regression] Writing a namelist with repeated complex numbers
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83191 --- Comment #4 from Jerry DeLisle --- Alternatively one could do this: @@ -1809,9 +1809,11 @@ write_complex (st_parameter_dt *dtp, const char *source, int kind, size_t size) precision, buf_size, result1, _len1); get_float_string (dtp, , source + size / 2 , kind, 0, buffer, precision, buf_size, result2, _len2); - lblanks = width - res_len1 - res_len2 - 3; - - write_x (dtp, lblanks, lblanks); + if (!dtp->u.p.namelist_mode) +{ + lblanks = width - res_len1 - res_len2 - 3; + write_x (dtp, lblanks, lblanks); +} write_char (dtp, '('); write_float_string (dtp, result1, res_len1); write_char (dtp, semi_comma);
[Bug fortran/83191] [7/8 Regression] Writing a namelist with repeated complex numbers
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83191 --- Comment #3 from Dominique d'Humieres --- The following patch does the trick: --- ../_clean/libgfortran/io/write.c2017-11-22 20:37:44.0 +0100 +++ libgfortran/io/write.c 2017-11-28 23:45:55.0 +0100 @@ -1552,7 +1552,7 @@ select_string (st_parameter_dt *dtp, con int kind) { char *result; - *size = size_from_kind (dtp, f, kind) + f->u.real.d; + *size = size_from_kind (dtp, f, kind) + f->u.real.d + 1; if (*size > BUF_STACK_SZ) result = xmalloc (*size); else @@ -1769,7 +1769,8 @@ write_real_g0 (st_parameter_dt *dtp, con static void -write_complex (st_parameter_dt *dtp, const char *source, int kind, size_t size) +write_complex (st_parameter_dt *dtp, const char *source, int kind, size_t size, + bool justify) { char semi_comma = dtp->u.p.current_unit->decimal_status == DECIMAL_POINT ? ',' : ';'; @@ -1809,9 +1810,12 @@ write_complex (st_parameter_dt *dtp, con precision, buf_size, result1, _len1); get_float_string (dtp, , source + size / 2 , kind, 0, buffer, precision, buf_size, result2, _len2); - lblanks = width - res_len1 - res_len2 - 3; + if (justify) +{ + lblanks = width - res_len1 - res_len2 - 3; - write_x (dtp, lblanks, lblanks); + write_x (dtp, lblanks, lblanks); +} write_char (dtp, '('); write_float_string (dtp, result1, res_len1); write_char (dtp, semi_comma); @@ -1889,7 +1893,7 @@ list_formatted_write_scalar (st_paramete write_real (dtp, p, kind); break; case BT_COMPLEX: - write_complex (dtp, p, kind, size); + write_complex (dtp, p, kind, size, true); break; case BT_CLASS: { @@ -2202,7 +2206,7 @@ nml_write_obj (st_parameter_dt *dtp, nam case BT_COMPLEX: dtp->u.p.no_leading_blank = 0; num++; - write_complex (dtp, p, len, obj_size); + write_complex (dtp, p, len, obj_size, false); break; case BT_DERIVED:
[Bug fortran/83191] [7/8 Regression] Writing a namelist with repeated complex numbers
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83191 Jerry DeLisle changed: What|Removed |Added Status|NEW |ASSIGNED Assignee|unassigned at gcc dot gnu.org |jvdelisle at gcc dot gnu.org --- Comment #2 from Jerry DeLisle --- My bad. I will look into it.
[Bug fortran/83191] [7/8 Regression] Writing a namelist with repeated complex numbers
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83191 Dominique d'Humieres changed: What|Removed |Added Priority|P3 |P4 Status|UNCONFIRMED |NEW Known to work||6.4.0 Keywords||wrong-code Last reconfirmed||2017-11-28 CC||jvdelisle at gcc dot gnu.org Ever confirmed|0 |1 Summary|Writing a namelist with |[7/8 Regression] Writing a |repeated complex numbers|namelist with repeated ||complex numbers Target Milestone|--- |7.3 Known to fail||7.2.0, 8.0 --- Comment #1 from Dominique d'Humieres --- Likely caused by r237735 (pr48852). The test in pr48852 comment 0 prints now (1.,0.) It should probably be (1.,0.) If I read the code correctly, it is caused by the lines lblanks = width - res_len1 - res_len2 - 3; write_x (dtp, lblanks, lblanks); needed to have right justified outputs (case C in pr48852 comment 12).