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);
}
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::
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. */
/* 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);
}
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;
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);
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);
}
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
#include "jit-common.h"
#include "jit-logging.h"
#include "jit-target.h"
+#include "diagnostic-core.h"
#include "libgccjit.h"
#include <string>
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;
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'");
}