https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120621

--- Comment #14 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Rainer Orth <r...@gcc.gnu.org>:

https://gcc.gnu.org/g:3e7dd06860bf0589bc743e458b16bd1d33d73835

commit r16-2192-g3e7dd06860bf0589bc743e458b16bd1d33d73835
Author: Rainer Orth <r...@cebitec.uni-bielefeld.de>
Date:   Fri Jul 11 09:56:18 2025 +0200

    cobol: Fix build on 32-bit Darwin [PR120621]

    Bootstrapping trunk with 32-bit-default on Mac OS X 10.11
    (i386-apple-darwin15) fails:

    /vol/gcc/src/hg/master/local/gcc/cobol/lexio.cc: In static member function
'static void cdftext::process_file(filespan_t, int, bool)':
    /vol/gcc/src/hg/master/local/gcc/cobol/lexio.cc:1859:14: error: format '%u'
expects argument of type 'unsigned int', but argument 4 has type 'size_t' {aka
'long unsigned int'} [-Werror=format=]
     1859 |       dbgmsg("%s:%d: line " HOST_SIZE_T_PRINT_UNSIGNED ", opening
%s on fd %d",
          |             
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     1860 |              __func__, __LINE__,mfile.lineno(),
          |                                 ~~~~~~~~~~~~~~
          |                                             |
          |                                             size_t {aka long
unsigned int}
    In file included from /vol/gcc/src/hg/master/local/gcc/system.h:1244,
                     from
/vol/gcc/src/hg/master/local/gcc/cobol/cobol-system.h:61,
                     from /vol/gcc/src/hg/master/local/gcc/cobol/lexio.cc:33:
    /vol/gcc/src/hg/master/local/gcc/hwint.h:135:51: note: format string is
defined here
      135 | #define HOST_SIZE_T_PRINT_UNSIGNED "%" GCC_PRISZ "u"
          |                                     ~~~~~~~~~~~~~~^
          |                                                   |
          |                                                   unsigned int
          |                                     %" GCC_PRISZ "lu

    On Darwin, size_t is always long unsigned int.  However, unsigned int
    and long unsigned int are both 32-bit, so hwint.h selects %u for the
    format.  As documented there, the arg needs to be cast to fmt_size_t to
    avoid the error.

    This isn't an issue on other 32-bit platforms like Solaris/i386 or
    Linux/i686 since they use unsigned int for size_t.

    /vol/gcc/src/hg/master/local/gcc/cobol/parse.y: In function 'int
yyparse()':
    /vol/gcc/src/hg/master/local/gcc/cobol/parse.y:10215:36: error: format
'%zu' expects argument of type 'size_t', but argument 4 has type 'int'
[-Werror=format=]
    10215 |                     error_msg(loc, "FUNCTION %qs has "
          |                                    ^~~~~~~~~~~~~~~~~~~
    10216 |                               "inconsistent parameter type %zu
(%qs)",
          |                              
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    10217 |                               keyword_str($1), p - args.data(),
name_of(p->field) );
          |                                                               
~~~~~~~~~~~~~~~
          |                                                                  |
          |                                                                 
int

    The arg (p - args.data())) is ptrdiff_t (int on 32-bit Darwin), while
    the %zu format expect size_t (long unsigned int).  The patch therefore
    casts the ptrdiff_t arg to long and prints it as such.

    There are two more instances of the same problem:

    /vol/gcc/src/hg/master/local/gcc/cobol/util.cc: In member function 'void
cbl_field_t::report_invalid_initial_value(const YYLTYPE&) const':
    /vol/gcc/src/hg/master/local/gcc/cobol/util.cc:905:80: error: format '%zu'
expects argument of type 'size_t', but argument 6 has type 'int'
[-Werror=format=]
      905 |                 error_msg(loc, "%s cannot represent VALUE %qs
exactly (max %c%zu)",
          |                                                                    
         ~~^
          |                                                                    
           |
          |                                                                    
           long unsigned int
          |                                                                    
         %u
      906 |                           name, data.initial, '.', pend - p);
          |                                                    ~~~~~~~~
          |                                                         |
          |                                                         int

    In file included from /vol/gcc/src/hg/master/local/gcc/cobol/scan.l:48:
    /vol/gcc/src/hg/master/local/gcc/cobol/scan_ante.h: In function 'int
numstr_of(const char*, radix_t)':
    /vol/gcc/src/hg/master/local/gcc/cobol/scan_ante.h:152:25: error: format
'%zu' expects argument of type 'size_t', but argument 4 has type 'int'
[-Werror=format=]
      152 |       error_msg(yylloc, "significand of %s has more than 36 digits
(%zu)", input, nx);
          |                        
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~         ~~
          |                                                                    
              |
          |                                                                    
              int

    Fixed in the same way.

    Bootstrapped without regressions on i386-apple-darwin15,
    x86_64-apple-darwin, i386-pc-solaris2.11, amd64-pc-solaris2.11,
    i686-pc-linux-gnu, and x86_64-pc-linux-gnu.

    2025-06-23  Rainer Orth  <r...@cebitec.uni-bielefeld.de>

            gcc/cobol:
            PR cobol/120621
            * lexio.cc (parse_replace_pairs): Cast mfile.lineno() to
fmt_size_t.
            * parse.y (intrinsic): Print ptrdiff_t using %ld, cast arg to long.
            * scan_ante.h (numstr_of): Print nx using %ld, cast arg to long.
            * util.cc (cbl_field_t::report_invalid_initial_value): Print
            ptrdiff_t using %ld, cast arg to long.

Reply via email to