From 1f1b7d2298956268e2678a157a34c8f9ac370f3a Mon Sep 17 00:00:00 2001 From: Antoni Boucher Date: Sun, 23 Jan 2022 11:37:07 -0500 Subject: [PATCH] libgccjit: Add function to hide stderr logs [PR104073] 2022-01-23 Antoni Boucher get_debug_string (), - errmsg); - else - fprintf (stderr, "%s: error: %s\n", - ctxt_progname, - errmsg); + bool print_errors_to_stderr = + get_inner_bool_option (INNER_BOOL_OPTION_PRINT_ERRORS_TO_STDERR); + if (print_errors_to_stderr) + { + if (loc) + fprintf (stderr, "%s: %s: error: %s\n", + ctxt_progname, + loc->get_debug_string (), + errmsg); + else + fprintf (stderr, "%s: error: %s\n", + ctxt_progname, + errmsg); + } if (!m_error_count) { @@ -1687,7 +1693,8 @@ static const char * const static const char * const inner_bool_option_reproducer_strings[NUM_INNER_BOOL_OPTIONS] = { "gcc_jit_context_set_bool_allow_unreachable_blocks", - "gcc_jit_context_set_bool_use_external_driver" + "gcc_jit_context_set_bool_use_external_driver", + "gcc_jit_context_set_bool_print_errors_to_stderr", }; /* Write the current value of all options to the log file (if any). */ diff --git a/gcc/jit/libgccjit.cc b/gcc/jit/libgccjit.cc index 4c352e8c93d..778f8e926a2 100644 --- a/gcc/jit/libgccjit.cc +++ b/gcc/jit/libgccjit.cc @@ -3431,6 +3431,23 @@ gcc_jit_context_set_bool_allow_unreachable_blocks (gcc_jit_context *ctxt, bool_value); } +/* Public entrypoint. See description in libgccjit.h. + + After error-checking, the real work is done by the + gcc::jit::recording::context::set_inner_bool_option method in + jit-recording.cc. */ + +void +gcc_jit_context_set_bool_print_errors_to_stderr (gcc_jit_context *ctxt, + int enabled) +{ + RETURN_IF_FAIL (ctxt, NULL, NULL, "NULL context"); + JIT_LOG_FUNC (ctxt->get_logger ()); + ctxt->set_inner_bool_option ( + gcc::jit::INNER_BOOL_OPTION_PRINT_ERRORS_TO_STDERR, + enabled); +} + /* Public entrypoint. See description in libgccjit.h. After error-checking, the real work is done by the diff --git a/gcc/jit/libgccjit.h b/gcc/jit/libgccjit.h index 2a5ffacb1fe..16b8637dd0a 100644 --- a/gcc/jit/libgccjit.h +++ b/gcc/jit/libgccjit.h @@ -293,6 +293,24 @@ gcc_jit_context_set_bool_allow_unreachable_blocks (gcc_jit_context *ctxt, tested for with #ifdef. */ #define LIBGCCJIT_HAVE_gcc_jit_context_set_bool_allow_unreachable_blocks +/* By default, libgccjit will print errors to stderr. + + This option can be used to disable the printing. + + This entrypoint was added in LIBGCCJIT_ABI_23; you can test for + its presence using + #ifdef LIBGCCJIT_HAVE_gcc_jit_context_set_bool_print_errors_to_stderr +*/ + +extern void +gcc_jit_context_set_bool_print_errors_to_stderr (gcc_jit_context *ctxt, + int enabled); + +/* Pre-canned feature macro to indicate the presence of + gcc_jit_context_set_bool_allow_unreachable_blocks. This can be + tested for with #ifdef. */ +#define LIBGCCJIT_HAVE_gcc_jit_context_set_bool_print_errors_to_stderr + /* Implementation detail: libgccjit internally generates assembler, and uses "driver" code for converting it to other formats (e.g. shared libraries). diff --git a/gcc/jit/libgccjit.map b/gcc/jit/libgccjit.map index f373fd39ac7..aa161b438c8 100644 --- a/gcc/jit/libgccjit.map +++ b/gcc/jit/libgccjit.map @@ -243,3 +243,17 @@ LIBGCCJIT_ABI_19 { gcc_jit_context_new_union_constructor; gcc_jit_global_set_initializer_rvalue; } LIBGCCJIT_ABI_18; + +LIBGCCJIT_ABI_20 { +} LIBGCCJIT_ABI_19; + +LIBGCCJIT_ABI_21 { +} LIBGCCJIT_ABI_20; + +LIBGCCJIT_ABI_22 { +} LIBGCCJIT_ABI_21; + +LIBGCCJIT_ABI_23 { + global: + gcc_jit_context_set_bool_print_errors_to_stderr; +} LIBGCCJIT_ABI_22; -- 2.26.2.7.g19db9cfb68.dirty