Skip to content

Commit 2fc8940

Browse files
committed
libgccjit: Do not treat warnings as errors
1 parent be000af commit 2fc8940

File tree

4 files changed

+40
-16
lines changed

4 files changed

+40
-16
lines changed

gcc/jit/jit-playback.cc

+6-7
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

+26-6
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,29 @@ 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, const char *fmt, ...)
1677+
{
1678+
va_list ap;
1679+
va_start (ap, fmt);
1680+
add_error_va (loc, diagnostic_kind, fmt, ap);
1681+
va_end (ap);
1682+
}
1683+
16671684
void
16681685
recording::context::add_error (location *loc, const char *fmt, ...)
16691686
{
16701687
va_list ap;
16711688
va_start (ap, fmt);
1672-
add_error_va (loc, fmt, ap);
1689+
add_error_va (loc, DK_ERROR, fmt, ap);
16731690
va_end (ap);
16741691
}
16751692

16761693
/* Format the given error using printf's conventions, print
16771694
it to stderr, and add it to the context. */
16781695

16791696
void
1680-
recording::context::add_error_va (location *loc, const char *fmt, va_list ap)
1697+
recording::context::add_error_va (location *loc, diagnostic_t diagnostic_kind, const char *fmt, va_list ap)
16811698
{
16821699
int len;
16831700
char *malloced_msg;
@@ -1698,7 +1715,7 @@ recording::context::add_error_va (location *loc, const char *fmt, va_list ap)
16981715
has_ownership = true;
16991716
}
17001717
if (get_logger ())
1701-
get_logger ()->log ("error %i: %s", m_error_count, errmsg);
1718+
get_logger ()->log ("%s %i: %s", diagnostic_kind_text[diagnostic_kind], m_error_count, errmsg);
17021719

17031720
const char *ctxt_progname =
17041721
get_str_option (GCC_JIT_STR_OPTION_PROGNAME);
@@ -1710,13 +1727,15 @@ recording::context::add_error_va (location *loc, const char *fmt, va_list ap)
17101727
if (print_errors_to_stderr)
17111728
{
17121729
if (loc)
1713-
fprintf (stderr, "%s: %s: error: %s\n",
1730+
fprintf (stderr, "%s: %s: %s: %s\n",
17141731
ctxt_progname,
17151732
loc->get_debug_string (),
1733+
diagnostic_kind_text[diagnostic_kind],
17161734
errmsg);
17171735
else
1718-
fprintf (stderr, "%s: error: %s\n",
1736+
fprintf (stderr, "%s: %s: %s\n",
17191737
ctxt_progname,
1738+
diagnostic_kind_text[diagnostic_kind],
17201739
errmsg);
17211740
}
17221741

@@ -1732,7 +1751,8 @@ recording::context::add_error_va (location *loc, const char *fmt, va_list ap)
17321751
m_last_error_str = const_cast <char *> (errmsg);
17331752
m_owns_last_error_str = has_ownership;
17341753

1735-
m_error_count++;
1754+
if (diagnostic_kind == DK_ERROR)
1755+
m_error_count++;
17361756
}
17371757

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

gcc/jit/jit-recording.h

+7-2
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,17 @@ class context : public log_user
320321
void
321322
get_target_info ();
322323

324+
void
325+
add_diagnostic (location *loc, diagnostic_t diagnostic_kind, const char *fmt, ...)
326+
GNU_PRINTF(4, 5);
327+
323328
void
324329
add_error (location *loc, const char *fmt, ...)
325330
GNU_PRINTF(3, 4);
326331

327332
void
328-
add_error_va (location *loc, const char *fmt, va_list ap)
329-
GNU_PRINTF(3, 0);
333+
add_error_va (location *loc, diagnostic_t diagnostic_kind, const char *fmt, va_list ap)
334+
GNU_PRINTF(4, 0);
330335

331336
const char *
332337
get_first_error () const;

gcc/jit/libgccjit.cc

+1-1
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. */

0 commit comments

Comments
 (0)