Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 4e65f02

Browse files
committedFeb 16, 2024
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.
1 parent 94076b9 commit 4e65f02

File tree

5 files changed

+48
-23
lines changed

5 files changed

+48
-23
lines changed
 

‎gcc/jit/jit-playback.cc

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3941,7 +3941,7 @@ add_error (location *loc, const char *fmt, ...)
39413941
va_list ap;
39423942
va_start (ap, fmt);
39433943
m_recording_ctxt->add_error_va (loc ? loc->get_recording_loc () : NULL,
3944-
fmt, ap);
3944+
DK_ERROR, fmt, ap);
39453945
va_end (ap);
39463946
}
39473947

@@ -3953,13 +3953,12 @@ playback::context::
39533953
add_error_va (location *loc, const char *fmt, va_list ap)
39543954
{
39553955
m_recording_ctxt->add_error_va (loc ? loc->get_recording_loc () : NULL,
3956-
fmt, ap);
3956+
DK_ERROR, fmt, ap);
39573957
}
39583958

3959-
/* Report a diagnostic up to the jit context as an error,
3960-
so that the compilation is treated as a failure.
3961-
For now, any kind of diagnostic is treated as an error by the jit
3962-
API. */
3959+
/* Report a diagnostic up to the jit context, so that the
3960+
compilation is treated as a failure if the diagnostic
3961+
is an error. */
39633962

39643963
void
39653964
playback::context::
@@ -3989,7 +3988,7 @@ add_diagnostic (diagnostic_context *diag_context,
39893988
false);
39903989
}
39913990

3992-
m_recording_ctxt->add_error (rec_loc, "%s", text);
3991+
m_recording_ctxt->add_diagnostic (rec_loc, diagnostic.kind, "%s", text);
39933992
pp_clear_output_area (pp);
39943993
}
39953994

‎gcc/jit/jit-recording.cc

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ along with GCC; see the file COPYING3. If not see
3131
#include "jit-playback.h"
3232
#include <sstream>
3333

34+
/* This comes from diagnostic.cc. */
35+
static const char *const diagnostic_kind_text[] = {
36+
#define DEFINE_DIAGNOSTIC_KIND(K, T, C) (T),
37+
#include "diagnostic.def"
38+
#undef DEFINE_DIAGNOSTIC_KIND
39+
"must-not-happen"
40+
};
41+
3442
namespace gcc {
3543
namespace jit {
3644

@@ -1664,20 +1672,31 @@ recording::context::get_target_info ()
16641672
/* Format the given error using printf's conventions, print
16651673
it to stderr, and add it to the context. */
16661674

1675+
void
1676+
recording::context::add_diagnostic (location *loc, diagnostic_t diagnostic_kind,
1677+
const char *fmt, ...)
1678+
{
1679+
va_list ap;
1680+
va_start (ap, fmt);
1681+
add_error_va (loc, diagnostic_kind, fmt, ap);
1682+
va_end (ap);
1683+
}
1684+
16671685
void
16681686
recording::context::add_error (location *loc, const char *fmt, ...)
16691687
{
16701688
va_list ap;
16711689
va_start (ap, fmt);
1672-
add_error_va (loc, fmt, ap);
1690+
add_error_va (loc, DK_ERROR, fmt, ap);
16731691
va_end (ap);
16741692
}
16751693

16761694
/* Format the given error using printf's conventions, print
16771695
it to stderr, and add it to the context. */
16781696

16791697
void
1680-
recording::context::add_error_va (location *loc, const char *fmt, va_list ap)
1698+
recording::context::add_error_va (location *loc, diagnostic_t diagnostic_kind,
1699+
const char *fmt, va_list ap)
16811700
{
16821701
int len;
16831702
char *malloced_msg;
@@ -1698,7 +1717,8 @@ recording::context::add_error_va (location *loc, const char *fmt, va_list ap)
16981717
has_ownership = true;
16991718
}
17001719
if (get_logger ())
1701-
get_logger ()->log ("error %i: %s", m_error_count, errmsg);
1720+
get_logger ()->log ("%s %i: %s", diagnostic_kind_text[diagnostic_kind],
1721+
m_error_count, errmsg);
17021722

17031723
const char *ctxt_progname =
17041724
get_str_option (GCC_JIT_STR_OPTION_PROGNAME);
@@ -1710,13 +1730,15 @@ recording::context::add_error_va (location *loc, const char *fmt, va_list ap)
17101730
if (print_errors_to_stderr)
17111731
{
17121732
if (loc)
1713-
fprintf (stderr, "%s: %s: error: %s\n",
1733+
fprintf (stderr, "%s: %s: %s: %s\n",
17141734
ctxt_progname,
17151735
loc->get_debug_string (),
1736+
diagnostic_kind_text[diagnostic_kind],
17161737
errmsg);
17171738
else
1718-
fprintf (stderr, "%s: error: %s\n",
1739+
fprintf (stderr, "%s: %s: %s\n",
17191740
ctxt_progname,
1741+
diagnostic_kind_text[diagnostic_kind],
17201742
errmsg);
17211743
}
17221744

@@ -1732,7 +1754,8 @@ recording::context::add_error_va (location *loc, const char *fmt, va_list ap)
17321754
m_last_error_str = const_cast <char *> (errmsg);
17331755
m_owns_last_error_str = has_ownership;
17341756

1735-
m_error_count++;
1757+
if (diagnostic_kind == DK_ERROR)
1758+
m_error_count++;
17361759
}
17371760

17381761
/* Get the message for the first error that occurred on this context, or

‎gcc/jit/jit-recording.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ along with GCC; see the file COPYING3. If not see
2323

2424
#include "jit-common.h"
2525
#include "jit-logging.h"
26+
#include "diagnostic-core.h"
2627
#include "libgccjit.h"
2728

2829
#include <string>
@@ -320,13 +321,19 @@ class context : public log_user
320321
void
321322
get_target_info ();
322323

324+
void
325+
add_diagnostic (location *loc, diagnostic_t diagnostic_kind,
326+
const char *fmt, ...)
327+
GNU_PRINTF(4, 5);
328+
323329
void
324330
add_error (location *loc, const char *fmt, ...)
325331
GNU_PRINTF(3, 4);
326332

327333
void
328-
add_error_va (location *loc, const char *fmt, va_list ap)
329-
GNU_PRINTF(3, 0);
334+
add_error_va (location *loc, diagnostic_t diagnostic_kind, const char *fmt,
335+
va_list ap)
336+
GNU_PRINTF(4, 0);
330337

331338
const char *
332339
get_first_error () const;

‎gcc/jit/libgccjit.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ jit_error (gcc::jit::recording::context *ctxt,
341341
va_start (ap, fmt);
342342

343343
if (ctxt)
344-
ctxt->add_error_va (loc, fmt, ap);
344+
ctxt->add_error_va (loc, DK_ERROR, fmt, ap);
345345
else
346346
{
347347
/* No context? Send to stderr. */

‎gcc/testsuite/jit.dg/test-error-array-bounds.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,7 @@ create_code (gcc_jit_context *ctxt, void *user_data)
6464
void
6565
verify_code (gcc_jit_context *ctxt, gcc_jit_result *result)
6666
{
67-
/* Verify that the diagnostic led to the context failing... */
68-
CHECK_VALUE (result, NULL);
69-
70-
/* ...and that the message was captured by the API. */
71-
CHECK_STRING_VALUE (gcc_jit_context_get_first_error (ctxt),
72-
"array subscript 10 is above array bounds of"
73-
" 'char[10]' [-Warray-bounds=]");
67+
/* Verify that the message was captured by the API. */
68+
CHECK_STRING_VALUE (gcc_jit_context_get_last_error (ctxt),
69+
"while referencing 'buffer'");
7470
}

0 commit comments

Comments
 (0)
Please sign in to comment.