Bootstrap with COBOL included is currently broken for 32-bit-default Solaris
configurations.  There are three issues:

gcc/cobol/lexio.cc: In static member function ‘static std::FILE* 
cdftext::lex_open(const char*)’:
gcc/cobol/lexio.cc:1527:55: error: format ‘%d’ expects argument of type ‘int’, 
but argument 2 has type ‘pid_t’ {aka ‘long int’} [-Werror=format=]
 1527 |     if( kid == -1 ) cbl_err( "failed waiting for pid %d", pid);
      |                                                      ~^   ~~~
      |                                                       |   |
      |                                                       int pid_t {aka 
long int}
      |                                                      %ld

<sys/types.h> has

#if defined(_LP64) || defined(_I32LPx)
typedef int     pid_t;                  /* process id type      */
#else
typedef long    pid_t;                  /* (historical version) */
#endif

To fix this, pid_t needs to be printed using %ld, casting the value to
long.

gcc/cobol/genapi.cc: In function ‘tree_node* parser_compile_ecs(const 
std::vector<long long unsigned int>&)’:
gcc/cobol/genapi.cc:960:44: error: format ‘%ld’ expects argument of type ‘long 
int’, but argument 4 has type ‘std::vector<long long unsigned int>::size_type’ 
{aka ‘unsigned int’} [-Werror=format=]
  960 |     snprintf(ach, sizeof(ach), " Size is %ld; retval is %p",
      |                                          ~~^
      |                                            |
      |                                            long int
      |                                          %d
  961 |              ecs.size(), as_voidp(retval));
      |              ~~~~~~~~~~                     
      |                      |
      |                      std::vector<long long unsigned int>::size_type 
{aka unsigned int}

size_type is std::size_t, which <iso/stddef_iso.h> defines as

#if defined(_LP64) || defined(_I32LPx) 
typedef unsigned long   size_t;         /* size of something in bytes */
#else
typedef unsigned int    size_t;         /* (historical version) */ 
#endif

Given that size_t is already printed using %zu in other cases, this
patch changes the remaining instances to match.

In file included from gcc/cobol/genapi.cc:33:
In function ‘tree_node* contains_struct_check(tree, tree_node_structure_enum, 
const char*, int, const char*)’,
    inlined from ‘void parser_division(cbl_division_t, cbl_field_t*, 
std::size_t, cbl_ffi_arg_t*)’ at gcc/cobol/genapi.cc:6938:25:
gcc/tree.h:324:56: error: ‘parameter’ may be used uninitialized 
[-Werror=maybe-uninitialized]
  324 | #define TREE_CODE(NODE) ((enum tree_code) (NODE)->base.code)
      |                                           ~~~~~~~~~~~~~^~~~
gcc/tree.h:3856:28: note: in expansion of macro ‘TREE_CODE’
 3856 |   if (tree_contains_struct[TREE_CODE (__t)][__s] != 1)
      |                            ^~~~~~~~~
gcc/cobol/genapi.cc: In function ‘void parser_division(cbl_division_t, 
cbl_field_t*, std::size_t, cbl_ffi_arg_t*)’:
gcc/cobol/genapi.cc:6901:12: note: ‘parameter’ was declared here
 6901 |       tree parameter;
      |            ^~~~~~~~~

This patch just initializes parameter to NULL_TREE to avoid this.

Bootstrapped without regressions on i386-pc-solaris2.11,
amd64-pc-solaris2.11, sparc-sun-solaris2.112, sparcv9-sun-solaris2.11,
i686-pc-linux-gnu, and x86_64-pc-linux-gnu.

Ok for trunk?

        Rainer

-- 
-----------------------------------------------------------------------------
Rainer Orth, Center for Biotechnology, Bielefeld University


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

        gcc/cobol:
        PR cobol/120621
        * lexio.cc (cdftext::lex_open): Print pid, kid as long.
        * scan_ante.h (wait_for_the_child): Likewise.

        * genapi.cc (parser_compile_ecs): Print size_t using %zu.
        (parser_compile_dcls): Likewise.
        (inspect_tally): Likewise.
        * parse.y (numstr2i): Print size_t using %zu.
        (literal_subscripts_valid): Likewise.

        * genapi.cc (parser_division): Initialize parameter.

# HG changeset patch
# Parent  b68b1d90d3a486919c23b685f12a61770cff6db3
cobol: Fix build on 32-bit Solaris

diff --git a/gcc/cobol/genapi.cc b/gcc/cobol/genapi.cc
--- a/gcc/cobol/genapi.cc
+++ b/gcc/cobol/genapi.cc
@@ -957,7 +957,7 @@ parser_compile_ecs( const std::vector<ui
     {
     SHOW_PARSE_HEADER
     char ach[64];
-    snprintf(ach, sizeof(ach), " Size is %ld; retval is %p",
+    snprintf(ach, sizeof(ach), " Size is %zu; retval is %p",
              ecs.size(), as_voidp(retval));
     SHOW_PARSE_TEXT(ach)
     SHOW_PARSE_END
@@ -966,7 +966,7 @@ parser_compile_ecs( const std::vector<ui
     {
     TRACE1_HEADER
     char ach[64];
-    snprintf(ach, sizeof(ach), " Size is %ld; retval is %p",
+    snprintf(ach, sizeof(ach), " Size is %zu; retval is %p",
              ecs.size(), as_voidp(retval));
     TRACE1_TEXT_ABC("", ach, "");
     TRACE1_END
@@ -1006,7 +1006,7 @@ parser_compile_dcls( const std::vector<u
     {
     SHOW_PARSE_HEADER
     char ach[64];
-    snprintf(ach, sizeof(ach), " Size is %ld; retval is %p",
+    snprintf(ach, sizeof(ach), " Size is %zu; retval is %p",
              dcls.size(), as_voidp(retval));
     SHOW_PARSE_TEXT(ach);
     SHOW_PARSE_END
@@ -1015,7 +1015,7 @@ parser_compile_dcls( const std::vector<u
     {
     TRACE1_HEADER
     char ach[64];
-    snprintf(ach, sizeof(ach), " Size is %ld; retval is %p",
+    snprintf(ach, sizeof(ach), " Size is %zu; retval is %p",
              dcls.size(), as_voidp(retval));
     TRACE1_TEXT_ABC("", ach, "");
     TRACE1_END
@@ -6898,7 +6898,7 @@ parser_division(cbl_division_t division,
 
       // There are 'nusing' elements in the PROCEDURE DIVISION USING list.
 
-      tree parameter;
+      tree parameter = NULL_TREE;
       tree rt_i = gg_define_int();
       for(size_t i=0; i<nusing; i++)
         {
@@ -9932,17 +9932,17 @@ inspect_tally(bool backward,
     {
     SHOW_PARSE_HEADER
     char ach[128];
-    sprintf(ach, "There are %lu identifier_2", identifier_2.size());
+    sprintf(ach, "There are %zu identifier_2", identifier_2.size());
     SHOW_PARSE_TEXT(ach);
     for(size_t i=0; i<identifier_2.size(); i++)
       {
       SHOW_PARSE_INDENT
-      sprintf(ach, "%lu: bounds: %lu", i, identifier_2[i].nbound());
+      sprintf(ach, "%zu: bounds: %zu", i, identifier_2[i].nbound());
       SHOW_PARSE_TEXT(ach);
       for(size_t j=0; j<identifier_2[i].nbound(); j++)
         {
         SHOW_PARSE_INDENT
-        sprintf(ach, "    %lu: matches: %lu", j, identifier_2[i][j].matches.size());
+        sprintf(ach, "    %zu: matches: %zu", j, identifier_2[i][j].matches.size());
         SHOW_PARSE_TEXT(ach);
 
         SHOW_PARSE_INDENT
diff --git a/gcc/cobol/lexio.cc b/gcc/cobol/lexio.cc
--- a/gcc/cobol/lexio.cc
+++ b/gcc/cobol/lexio.cc
@@ -1524,11 +1524,11 @@ cdftext::lex_open( const char filename[]
     int status;
     auto kid = wait(&status);
     gcc_assert(pid == kid);
-    if( kid == -1 ) cbl_err( "failed waiting for pid %d", pid);
+    if( kid == -1 ) cbl_err( "failed waiting for pid %ld", (long) pid);
 
     if( WIFSIGNALED(status) ) {
-      cbl_errx( "%s pid %d terminated by %s",
-           filter, kid, strsignal(WTERMSIG(status)) );
+      cbl_errx( "%s pid %ld terminated by %s",
+	filter, (long) kid, strsignal(WTERMSIG(status)) );
     }
     if( WIFEXITED(status) ) {
       if( (status = WEXITSTATUS(status)) != 0 ) {
diff --git a/gcc/cobol/parse.y b/gcc/cobol/parse.y
--- a/gcc/cobol/parse.y
+++ b/gcc/cobol/parse.y
@@ -12359,7 +12359,7 @@ numstr2i( const char input[], radix_t ra
     return output;
   }
   if( erc == -1 ) {
-    yywarn("'%s' was accepted as %wd", input, integer);
+    yywarn("'%s' was accepted as %zu", input, integer);
   }
   return output;
 }
@@ -13141,7 +13141,7 @@ literal_subscripts_valid( YYLTYPE loc, c
 
     // X(0): subscript 1 of for out of range for 02 X OCCURS 4 to 6
     error_msg(loc, "%s(%s): subscript %zu out of range "
-                   "for %s %s OCCURS %lu%s",
+                   "for %s %s OCCURS %zu%s",
 	      oob->name, subscript_names.c_str(), 1 + isub,
 	      oob->level_str(), oob->name,
 	      oob->occurs.bounds.lower, upper_phrase );
diff --git a/gcc/cobol/scan_ante.h b/gcc/cobol/scan_ante.h
--- a/gcc/cobol/scan_ante.h
+++ b/gcc/cobol/scan_ante.h
@@ -824,17 +824,18 @@ wait_for_the_child(void) {
   }
 
   if( WIFSIGNALED(status) ) {
-    yywarn( "process %d terminated by %s", pid, strsignal(WTERMSIG(status)) );
+    yywarn( "process %ld terminated by %s", (long) pid,
+	    strsignal(WTERMSIG(status)) );
     return false;
   }
   if( WIFEXITED(status) ) {
     if( WEXITSTATUS(status) != 0 ) {
-      yywarn("process %d exited with status %d", pid, status);
+      yywarn("process %ld exited with status %d", (long) pid, status);
       return false;
     }
   }
   if( yy_flex_debug ) {
-    yywarn("process %d exited with status %d", pid, status);
+    yywarn("process %ld exited with status %d", (long) pid, status);
   }
   return true;
 }

Reply via email to