From df879e7adfcef471703950ef0652e8a6e4fde0f4 Mon Sep 17 00:00:00 2001 From: Antoni Boucher Date: Mon, 12 Feb 2024 19:49:43 -0400 Subject: [PATCH] libgccjit: Do not treat warnings as errors gcc/jit/ChangeLog: * jit-playback.cc (add_error, add_error_va): Send DK_ERROR to add_error_va. (add_diagnostic): Call add_diagnostic instead of add_error. * jit-recording.cc (DEFINE_DIAGNOSTIC_KIND): New define. (recording::context::add_diagnostic): New function. (recording::context::add_error): Send DK_ERROR to add_error_va. (recording::context::add_error_va): New parameter diagnostic_kind. * jit-recording.h (add_diagnostic): New function. (add_error_va): New parameter diagnostic_kind. * libgccjit.cc (jit_error): Send DK_ERROR to add_error_va. gcc/testsuite/ChangeLog: * jit.dg/test-error-array-bounds.c: Fix test. --- gcc/jit/jit-playback.cc | 13 ++++----- gcc/jit/jit-recording.cc | 28 +++++++++++++++---- gcc/jit/jit-recording.h | 12 ++++++-- gcc/jit/libgccjit.cc | 2 +- .../jit.dg/test-error-array-bounds.c | 10 ++----- 5 files changed, 42 insertions(+), 23 deletions(-) diff --git a/gcc/jit/jit-playback.cc b/gcc/jit/jit-playback.cc index 291ddeb2cca2..63468d7367a6 100644 --- a/gcc/jit/jit-playback.cc +++ b/gcc/jit/jit-playback.cc @@ -3871,7 +3871,7 @@ add_error (location *loc, const char *fmt, ...) va_list ap; va_start (ap, fmt); m_recording_ctxt->add_error_va (loc ? loc->get_recording_loc () : NULL, - fmt, ap); + diagnostics::kind::error, fmt, ap); va_end (ap); } @@ -3883,13 +3883,12 @@ playback::context:: add_error_va (location *loc, const char *fmt, va_list ap) { m_recording_ctxt->add_error_va (loc ? loc->get_recording_loc () : NULL, - fmt, ap); + diagnostics::kind::error, fmt, ap); } -/* Report a diagnostic up to the jit context as an error, - so that the compilation is treated as a failure. - For now, any kind of diagnostic is treated as an error by the jit - API. */ +/* Report a diagnostic up to the jit context, so that the + compilation is treated as a failure if the diagnostic + is an error. */ void playback::context:: @@ -3914,7 +3913,7 @@ add_diagnostic (const char *text, false); } - m_recording_ctxt->add_error (rec_loc, "%s", text); + m_recording_ctxt->add_diagnostic (rec_loc, diagnostic.m_kind, "%s", text); } /* Dealing with the linemap API. */ diff --git a/gcc/jit/jit-recording.cc b/gcc/jit/jit-recording.cc index 6384565384bc..18e40356117c 100644 --- a/gcc/jit/jit-recording.cc +++ b/gcc/jit/jit-recording.cc @@ -1728,12 +1728,22 @@ recording::context::populate_target_info () /* Format the given error using printf's conventions, print it to stderr, and add it to the context. */ +void +recording::context::add_diagnostic (location *loc, + diagnostics::kind diagnostic_kind, const char *fmt, ...) +{ + va_list ap; + va_start (ap, fmt); + add_error_va (loc, diagnostic_kind, fmt, ap); + va_end (ap); +} + void recording::context::add_error (location *loc, const char *fmt, ...) { va_list ap; va_start (ap, fmt); - add_error_va (loc, fmt, ap); + add_error_va (loc, diagnostics::kind::error, fmt, ap); va_end (ap); } @@ -1741,7 +1751,8 @@ recording::context::add_error (location *loc, const char *fmt, ...) it to stderr, and add it to the context. */ void -recording::context::add_error_va (location *loc, const char *fmt, va_list ap) +recording::context::add_error_va (location *loc, + diagnostics::kind diagnostic_kind, const char *fmt, va_list ap) { int len; char *malloced_msg; @@ -1762,7 +1773,9 @@ recording::context::add_error_va (location *loc, const char *fmt, va_list ap) has_ownership = true; } if (get_logger ()) - get_logger ()->log ("error %i: %s", m_error_count, errmsg); + get_logger ()->log ("%s %i: %s", + diagnostics::get_text_for_kind (diagnostic_kind), + m_error_count, errmsg); const char *ctxt_progname = get_str_option (GCC_JIT_STR_OPTION_PROGNAME); @@ -1774,13 +1787,15 @@ recording::context::add_error_va (location *loc, const char *fmt, va_list ap) if (print_errors_to_stderr) { if (loc) - fprintf (stderr, "%s: %s: error: %s\n", + fprintf (stderr, "%s: %s: %s: %s\n", ctxt_progname, loc->get_debug_string (), + diagnostics::get_text_for_kind (diagnostic_kind), errmsg); else - fprintf (stderr, "%s: error: %s\n", + fprintf (stderr, "%s: %s: %s\n", ctxt_progname, + diagnostics::get_text_for_kind (diagnostic_kind), errmsg); } @@ -1796,7 +1811,8 @@ recording::context::add_error_va (location *loc, const char *fmt, va_list ap) m_last_error_str = const_cast (errmsg); m_owns_last_error_str = has_ownership; - m_error_count++; + if (diagnostic_kind == diagnostics::kind::error) + m_error_count++; } /* Get the message for the first error that occurred on this context, or diff --git a/gcc/jit/jit-recording.h b/gcc/jit/jit-recording.h index 73a0b0663489..eeddfbcbb659 100644 --- a/gcc/jit/jit-recording.h +++ b/gcc/jit/jit-recording.h @@ -24,6 +24,7 @@ along with GCC; see the file COPYING3. If not see #include "jit-common.h" #include "jit-logging.h" #include "jit-target.h" +#include "diagnostic-core.h" #include "libgccjit.h" #include @@ -345,13 +346,20 @@ public: return info; } + void + add_diagnostic (location *loc, enum diagnostics::kind diagnostic_kind, + const char *fmt, ...) + GNU_PRINTF (4, 5); + void add_error (location *loc, const char *fmt, ...) GNU_PRINTF(3, 4); void - add_error_va (location *loc, const char *fmt, va_list ap) - GNU_PRINTF(3, 0); + add_error_va (location *loc, enum diagnostics::kind diagnostic_kind, + const char *fmt, + va_list ap) + GNU_PRINTF (4, 0); const char * get_first_error () const; diff --git a/gcc/jit/libgccjit.cc b/gcc/jit/libgccjit.cc index 886ca4d44b49..081b87b4066b 100644 --- a/gcc/jit/libgccjit.cc +++ b/gcc/jit/libgccjit.cc @@ -342,7 +342,7 @@ jit_error (gcc::jit::recording::context *ctxt, va_start (ap, fmt); if (ctxt) - ctxt->add_error_va (loc, fmt, ap); + ctxt->add_error_va (loc, diagnostics::kind::error, fmt, ap); else { /* No context? Send to stderr. */ diff --git a/gcc/testsuite/jit.dg/test-error-array-bounds.c b/gcc/testsuite/jit.dg/test-error-array-bounds.c index a0dead13cb74..fb5c20641773 100644 --- a/gcc/testsuite/jit.dg/test-error-array-bounds.c +++ b/gcc/testsuite/jit.dg/test-error-array-bounds.c @@ -64,11 +64,7 @@ create_code (gcc_jit_context *ctxt, void *user_data) void verify_code (gcc_jit_context *ctxt, gcc_jit_result *result) { - /* Verify that the diagnostic led to the context failing... */ - CHECK_VALUE (result, NULL); - - /* ...and that the message was captured by the API. */ - CHECK_STRING_VALUE (gcc_jit_context_get_first_error (ctxt), - "array subscript 10 is above array bounds of" - " 'char[10]' [-Warray-bounds=]"); + /* Verify that the message was captured by the API. */ + CHECK_STRING_VALUE (gcc_jit_context_get_last_error (ctxt), + "while referencing 'buffer'"); } -- 2.47.3