]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libgccjit: Do not treat warnings as errors
authorAntoni Boucher <bouanto@zoho.com>
Mon, 12 Feb 2024 23:49:43 +0000 (19:49 -0400)
committerAntoni Boucher <bouanto@zoho.com>
Mon, 20 Oct 2025 21:35:50 +0000 (17:35 -0400)
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
gcc/jit/jit-recording.cc
gcc/jit/jit-recording.h
gcc/jit/libgccjit.cc
gcc/testsuite/jit.dg/test-error-array-bounds.c

index 291ddeb2cca2f5e79a4e5681010457fceeaf0a3f..63468d7367a60c33e710edca4015fc832123d49d 100644 (file)
@@ -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.  */
index 6384565384bc2b1bbdbae5fe83d807265de8ffbc..18e40356117c99455af67b0c71b5675e05229175 100644 (file)
@@ -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 <char *> (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
index 73a0b06634895305376ee866a952ab0e44d2ef28..eeddfbcbb659a98eec538965e2c98afc0af717ab 100644 (file)
@@ -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 <string>
@@ -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;
index 886ca4d44b4985a0eb914f5fc7f707dd20a63db2..081b87b4066b3a1d7c22e7e9f64a780400e413c8 100644 (file)
@@ -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.  */
index a0dead13cb74902d3d1e5a8f8c45012584a02112..fb5c20641773e0926e2217096268066b546db1d0 100644 (file)
@@ -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'");
 }