Skip to content

Commit 297b735

Browse files
committed
libgccjit: Add function to hide stderr logs [PR104073]
2022-01-23 Antoni Boucher <[email protected] gcc/jit/ PR jit/104073 jit-common.h: New enum value (INNER_BOOL_OPTION_PRINT_ERRORS_TO_STDERR). jit.recording.cc: Handle the new option INNER_BOOL_OPTION_PRINT_ERRORS_TO_STDERR. libgccjit.cc: New function (gcc_jit_context_set_bool_print_errors_to_stderr). libgccjit.h: New function (gcc_jit_context_set_bool_print_errors_to_stderr). libgccjit.map (LIBGCCJIT_ABI_23): New ABI tag.
1 parent 7d7e2ba commit 297b735

File tree

5 files changed

+58
-10
lines changed

5 files changed

+58
-10
lines changed

gcc/jit/jit-common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ enum inner_bool_option
198198
{
199199
INNER_BOOL_OPTION_ALLOW_UNREACHABLE_BLOCKS,
200200
INNER_BOOL_OPTION_USE_EXTERNAL_DRIVER,
201+
INNER_BOOL_OPTION_PRINT_ERRORS_TO_STDERR,
201202

202203
NUM_INNER_BOOL_OPTIONS
203204
};

gcc/jit/jit-recording.cc

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,7 @@ recording::context::context (context *parent_ctxt)
592592
memset (m_int_options, 0, sizeof (m_int_options));
593593
memset (m_bool_options, 0, sizeof (m_bool_options));
594594
memset (m_inner_bool_options, 0, sizeof (m_inner_bool_options));
595+
m_inner_bool_options[INNER_BOOL_OPTION_PRINT_ERRORS_TO_STDERR] = true;
595596
}
596597

597598
memset (m_basic_types, 0, sizeof (m_basic_types));
@@ -1571,15 +1572,20 @@ recording::context::add_error_va (location *loc, const char *fmt, va_list ap)
15711572
if (!ctxt_progname)
15721573
ctxt_progname = "libgccjit.so";
15731574

1574-
if (loc)
1575-
fprintf (stderr, "%s: %s: error: %s\n",
1576-
ctxt_progname,
1577-
loc->get_debug_string (),
1578-
errmsg);
1579-
else
1580-
fprintf (stderr, "%s: error: %s\n",
1581-
ctxt_progname,
1582-
errmsg);
1575+
bool print_errors_to_stderr =
1576+
get_inner_bool_option (INNER_BOOL_OPTION_PRINT_ERRORS_TO_STDERR);
1577+
if (print_errors_to_stderr)
1578+
{
1579+
if (loc)
1580+
fprintf (stderr, "%s: %s: error: %s\n",
1581+
ctxt_progname,
1582+
loc->get_debug_string (),
1583+
errmsg);
1584+
else
1585+
fprintf (stderr, "%s: error: %s\n",
1586+
ctxt_progname,
1587+
errmsg);
1588+
}
15831589

15841590
if (!m_error_count)
15851591
{
@@ -1707,7 +1713,8 @@ static const char * const
17071713
static const char * const
17081714
inner_bool_option_reproducer_strings[NUM_INNER_BOOL_OPTIONS] = {
17091715
"gcc_jit_context_set_bool_allow_unreachable_blocks",
1710-
"gcc_jit_context_set_bool_use_external_driver"
1716+
"gcc_jit_context_set_bool_use_external_driver",
1717+
"gcc_jit_context_set_bool_print_errors_to_stderr",
17111718
};
17121719

17131720
/* Write the current value of all options to the log file (if any). */

gcc/jit/libgccjit.cc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3484,6 +3484,23 @@ gcc_jit_context_set_bool_allow_unreachable_blocks (gcc_jit_context *ctxt,
34843484
bool_value);
34853485
}
34863486

3487+
/* Public entrypoint. See description in libgccjit.h.
3488+
3489+
After error-checking, the real work is done by the
3490+
gcc::jit::recording::context::set_inner_bool_option method in
3491+
jit-recording.cc. */
3492+
3493+
void
3494+
gcc_jit_context_set_bool_print_errors_to_stderr (gcc_jit_context *ctxt,
3495+
int enabled)
3496+
{
3497+
RETURN_IF_FAIL (ctxt, NULL, NULL, "NULL context");
3498+
JIT_LOG_FUNC (ctxt->get_logger ());
3499+
ctxt->set_inner_bool_option (
3500+
gcc::jit::INNER_BOOL_OPTION_PRINT_ERRORS_TO_STDERR,
3501+
enabled);
3502+
}
3503+
34873504
/* Public entrypoint. See description in libgccjit.h.
34883505
34893506
After error-checking, the real work is done by the

gcc/jit/libgccjit.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,24 @@ gcc_jit_context_set_bool_allow_unreachable_blocks (gcc_jit_context *ctxt,
293293
tested for with #ifdef. */
294294
#define LIBGCCJIT_HAVE_gcc_jit_context_set_bool_allow_unreachable_blocks
295295

296+
/* By default, libgccjit will print errors to stderr.
297+
298+
This option can be used to disable the printing.
299+
300+
This entrypoint was added in LIBGCCJIT_ABI_23; you can test for
301+
its presence using
302+
#ifdef LIBGCCJIT_HAVE_gcc_jit_context_set_bool_print_errors_to_stderr
303+
*/
304+
305+
extern void
306+
gcc_jit_context_set_bool_print_errors_to_stderr (gcc_jit_context *ctxt,
307+
int enabled);
308+
309+
/* Pre-canned feature macro to indicate the presence of
310+
gcc_jit_context_set_bool_allow_unreachable_blocks. This can be
311+
tested for with #ifdef. */
312+
#define LIBGCCJIT_HAVE_gcc_jit_context_set_bool_print_errors_to_stderr
313+
296314
/* Implementation detail:
297315
libgccjit internally generates assembler, and uses "driver" code
298316
for converting it to other formats (e.g. shared libraries).

gcc/jit/libgccjit.map

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,3 +259,8 @@ LIBGCCJIT_ABI_21 {
259259
LIBGCCJIT_ABI_22 {
260260
gcc_jit_context_new_bitcast;
261261
} LIBGCCJIT_ABI_21;
262+
263+
LIBGCCJIT_ABI_23 {
264+
global:
265+
gcc_jit_context_set_bool_print_errors_to_stderr;
266+
} LIBGCCJIT_ABI_22;

0 commit comments

Comments
 (0)