>From 501f95ffae0371e2335f89951a02a3a32f0cd53d Mon Sep 17 00:00:00 2001
From: Robert Dubner mailto:rdub...@symas.com
Date: Sun, 1 Jun 2025 12:32:37 -0400
Subject: [PATCH] [PR119524]

---
 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 91f67d534f6..a5f143cf234 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 6721dd20740..9fd160b7083 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
@@ -13159,3 +13160,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);
+  }
+
-- 
2.34.1

Reply via email to