https://gcc.gnu.org/g:66c7519bbbbb9daa7edd24c16972948f10ec8ef9

commit r16-8454-g66c7519bbbbb9daa7edd24c16972948f10ec8ef9
Author: Jerry DeLisle <[email protected]>
Date:   Fri Apr 3 10:17:03 2026 -0700

    fortran: Minor adjustment to INQUIRE for ENCODING=
    
            PR libfortran/124543
    
    libgfortran/ChangeLog:
    
            * io/inquire.c (inquire_via_unit): Adjust the logic to
            treat formatted vs unformatted correctly.
    
    gcc/testsuite/ChangeLog:
    
            * gfortran.dg/pr124543.f90: Set result to 'UNDEFINED' in two
            places.

Diff:
---
 gcc/testsuite/gfortran.dg/pr124543.f90 | 4 ++--
 libgfortran/io/inquire.c               | 8 +++++---
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/gcc/testsuite/gfortran.dg/pr124543.f90 
b/gcc/testsuite/gfortran.dg/pr124543.f90
index 7a7f15dd3915..2ab5b5a023b4 100644
--- a/gcc/testsuite/gfortran.dg/pr124543.f90
+++ b/gcc/testsuite/gfortran.dg/pr124543.f90
@@ -202,7 +202,7 @@ program inq_tests
   inquire (unit=lun, decimal=decimal, encoding=encoding, pos=pos,  &
       round=round, sign=signc, stream=stream, iostat=iostat)
   if  (decimal /= 'POINT' .or. (iostat /= 0)) stop 204
-  if  (encoding /= 'UNKNOWN') stop 205
+  if  (encoding /= 'UNDEFINED') stop 205
   if  (round /= 'PROCESSOR_DEFINED') stop 206
   if  (signc /= 'PROCESSOR_DEFINED') stop 207
   if  (stream /= 'NO') stop 208
@@ -284,7 +284,7 @@ program inq_tests
   inquire (unit=lun, decimal=decimal, encoding=encoding, pos=pos,  &
       round=round, sign=signc, stream=stream, iostat=iostat)
   if  (decimal /= 'UNDEFINED' .or. (iostat /= 0)) stop 286
-  if  (encoding /= 'UNKNOWN') stop 287
+  if  (encoding /= 'UNDEFINED') stop 287
   if  (round /= 'PROCESSOR_DEFINED') stop 288
   if  (signc /= 'PROCESSOR_DEFINED') stop 289
   if  (stream /= 'YES') stop 290
diff --git a/libgfortran/io/inquire.c b/libgfortran/io/inquire.c
index f96210f1d57a..4d773349fa37 100644
--- a/libgfortran/io/inquire.c
+++ b/libgfortran/io/inquire.c
@@ -311,13 +311,13 @@ inquire_via_unit (st_parameter_inquire *iqp, gfc_unit *u)
 
       if ((cf2 & IOPARM_INQUIRE_HAS_ENCODING) != 0)
        {
-         if (u == NULL || u->flags.form != FORM_FORMATTED)
+         if (u == NULL)
            p = "UNKNOWN";
-          else
+         else if (u->flags.form == FORM_FORMATTED)
            switch (u->flags.encoding)
              {
              case ENCODING_DEFAULT:
-               p = "UNKNOWN";
+               p = "UNDEFINED";
                break;
              case ENCODING_UTF8:
                p = "UTF-8";
@@ -325,6 +325,8 @@ inquire_via_unit (st_parameter_inquire *iqp, gfc_unit *u)
              default:
                internal_error (&iqp->common, "inquire_via_unit(): Bad 
encoding");
              }
+           else
+             p = "UNKNOWN";
 
          cf_strcpy (iqp->encoding, iqp->encoding_len, p);
        }

Reply via email to