]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
cobol: Wrap the call to fprintf in a libgcobol routine. [PR119524]
authorRobert Dubner <rdubner@symas.com>
Sun, 1 Jun 2025 16:32:37 +0000 (12:32 -0400)
committerRobert Dubner <rdubner@symas.com>
Sun, 1 Jun 2025 16:42:22 +0000 (12:42 -0400)
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.

gcc/cobol/gengen.cc
libgcobol/libgcobol.cc

index 91f67d534f6eb269afc2c0d4d361c9649033fa65..a5f143cf2342730bc365f00ec0b23feceafe42cb 100644 (file)
@@ -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
index 66405baf99b1ca9609321d2863d6f8dbc19b7267..3ab74636601bea9adf285ca1a15bf916edae3921 100644 (file)
@@ -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);
+  }
+