From: Robert Dubner Date: Sun, 1 Jun 2025 16:32:37 +0000 (-0400) Subject: cobol: Wrap the call to fprintf in a libgcobol routine. [PR119524] X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=213cb633e7ec9b291768a4da0cd6d67679221aeb;p=thirdparty%2Fgcc.git 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 --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 66405baf99b..3ab74636601 100644 --- a/libgcobol/libgcobol.cc +++ b/libgcobol/libgcobol.cc @@ -49,6 +49,7 @@ #include #include #include +#include #if __has_include() # include // 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); + } +