https://gcc.gnu.org/g:213cb633e7ec9b291768a4da0cd6d67679221aeb

commit r16-1038-g213cb633e7ec9b291768a4da0cd6d67679221aeb
Author: Robert Dubner <rdub...@symas.com>
Date:   Sun Jun 1 12:32:37 2025 -0400

    cobol: Wrap the call to fprintf in a libgcobol routine. [PR119524]
    
    gcc/cobol/ChangeLog:
    
            PR cobol/119524
            * gengen.cc (gg_printf): Use the new __gg__fprintf_stderr() function
            instead of generating a call to fprintf().
    
    libgcobol/ChangeLog:
    
            PR cobol/119524
            * libgcobol.cc (__gg__fprintf_stderr): New function.

Diff:
---
 gcc/cobol/gengen.cc    | 16 +---------------
 libgcobol/libgcobol.cc | 14 ++++++++++++++
 2 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/gcc/cobol/gengen.cc b/gcc/cobol/gengen.cc
index 91f67d534f6e..a5f143cf2342 100644
--- a/gcc/cobol/gengen.cc
+++ b/gcc/cobol/gengen.cc
@@ -2152,18 +2152,6 @@ gg_printf(const char *format_string, ...)
   int nargs = 0;
   tree args[ARG_LIMIT];
 
-  // Because this routine is intended for debugging, we are sending the
-  // text to STDERR
-
-  // Because we don't actually use stderr ourselves, we just pick it up as a
-  // VOID_P and pass it along to fprintf()
-  tree t_stderr = gg_declare_variable(VOID_P, "stderr",
-                                      NULL_TREE,
-                                      vs_external_reference);
-
-  gg_push_context();
-
-  args[nargs++] = t_stderr;
   args[nargs++] = build_string_literal(strlen(format_string)+1, format_string);
 
   va_list ap;
@@ -2197,7 +2185,7 @@ gg_printf(const char *format_string, ...)
   static tree function = NULL_TREE;
   if( !function )
     {
-    function = gg_get_function_address(INT, "fprintf");
+    function = gg_get_function_address(INT, "__gg__fprintf_stderr");
     }
 
   tree stmt = build_call_array_loc (location_from_lineno(),
@@ -2206,8 +2194,6 @@ gg_printf(const char *format_string, ...)
                                     nargs,
                                     args);
   gg_append_statement(stmt);
-
-  gg_pop_context();
   }
 
 tree
diff --git a/libgcobol/libgcobol.cc b/libgcobol/libgcobol.cc
index 66405baf99b1..3ab74636601b 100644
--- a/libgcobol/libgcobol.cc
+++ b/libgcobol/libgcobol.cc
@@ -49,6 +49,7 @@
 #include <signal.h>
 #include <syslog.h>
 #include <unistd.h>
+#include <stdarg.h>
 #if __has_include(<errno.h>)
 # include <errno.h> // for program_invocation_short_name
 #endif
@@ -13151,3 +13152,16 @@ __gg__set_env_value(cblc_field_t   *value,
   // And now, anticlimactically, set the variable:
   setenv(trimmed_env, trimmed_val, 1);
   }
+
+extern "C"
+void
+__gg__fprintf_stderr(const char *format_string, ...)
+  {
+  /*  This routine allows the compiler to send stuff to stderr in a way
+      that is straightforward to use..  */
+  va_list ap;
+  va_start(ap, format_string);
+  vfprintf(stderr, format_string, ap);
+  va_end(ap);
+  }
+

Reply via email to