best_candidates.emit_best (this, eg);
}
-/* Custom subclass of diagnostic_metadata which, for SARIF output,
+/* Custom subclass of diagnostics::metadata which, for SARIF output,
populates the property bag of the diagnostic's "result" object
with information from the saved_diagnostic and the
pending_diagnostic. */
-class pending_diagnostic_metadata : public diagnostic_metadata
+class pending_diagnostic_metadata : public diagnostics::metadata
{
public:
pending_diagnostic_metadata (const saved_diagnostic &sd)
/* SEI CERT C Coding Standard: "POS34-C. Do not call putenv() with a
pointer to an automatic variable as the argument". */
- diagnostic_metadata::precanned_rule
+ diagnostics::metadata::precanned_rule
rule ("POS34-C", "https://wiki.sei.cmu.edu/confluence/x/6NYxBQ");
ctxt.add_rule (rule);
#ifndef GCC_ANALYZER_PENDING_DIAGNOSTIC_H
#define GCC_ANALYZER_PENDING_DIAGNOSTIC_H
-#include "diagnostic-metadata.h"
+#include "diagnostics/metadata.h"
#include "diagnostic-path.h"
#include "analyzer/sm.h"
public:
diagnostic_emission_context (const saved_diagnostic &sd,
rich_location &rich_loc,
- diagnostic_metadata &metadata,
+ diagnostics::metadata &metadata,
logger *logger)
: m_sd (sd),
m_rich_loc (rich_loc),
logger *get_logger () const { return m_logger; }
void add_cwe (int cwe) { m_metadata.add_cwe (cwe); }
- void add_rule (const diagnostic_metadata::rule &r)
+ void add_rule (const diagnostics::metadata::rule &r)
{
m_metadata.add_rule (r);
}
private:
const saved_diagnostic &m_sd;
rich_location &m_rich_loc;
- diagnostic_metadata &m_metadata;
+ diagnostics::metadata &m_metadata;
logger *m_logger;
};
#include <intl.h>
#include <backtrace.h>
#include <diagnostic.h>
-#include <diagnostic-color.h>
-#include <diagnostic-url.h>
-#include <diagnostic-metadata.h>
-#include <diagnostic-path.h>
-#include <edit-context.h>
-#include <selftest.h>
-#include <selftest-diagnostic.h>
#include <opts.h>
-
#include "util.h"
#include "cbldiag.h"
};
/* Forward decl. */
-class diagnostic_metadata; /* See diagnostic-metadata.h. */
+namespace diagnostics {
+ class metadata; /* See diagnostics/metadata.h. */
+} // namespace diagnostics
/* A class to use for the ID of an option that controls
a particular diagnostic.
const char *, ...)
ATTRIBUTE_GCC_DIAG(3,4);
extern bool warning_meta (rich_location *,
- const diagnostic_metadata &,
+ const diagnostics::metadata &,
diagnostic_option_id,
const char *, ...)
ATTRIBUTE_GCC_DIAG(4,5);
extern void error_at (location_t, const char *, ...) ATTRIBUTE_GCC_DIAG(2,3);
extern void error_at (rich_location *, const char *, ...)
ATTRIBUTE_GCC_DIAG(2,3);
-extern void error_meta (rich_location *, const diagnostic_metadata &,
+extern void error_meta (rich_location *, const diagnostics::metadata &,
const char *, ...)
ATTRIBUTE_GCC_DIAG(3,4);
extern void fatal_error (location_t, const char *, ...) ATTRIBUTE_GCC_DIAG(2,3)
ATTRIBUTE_GCC_DIAG (4,0);
extern bool emit_diagnostic_valist_meta (diagnostic_t,
rich_location *,
- const diagnostic_metadata *,
+ const diagnostics::metadata *,
diagnostic_option_id,
const char *,
va_list *) ATTRIBUTE_GCC_DIAG (5,0);
#include "system.h"
#include "coretypes.h"
#include "diagnostic.h"
-#include "diagnostic-metadata.h"
+#include "diagnostics/metadata.h"
#include "diagnostic-format.h"
#include "diagnostic-format-html.h"
#include "diagnostic-format-text.h"
}
std::unique_ptr<xml::element>
- make_element_for_metadata (const diagnostic_metadata &metadata);
+ make_element_for_metadata (const metadata &);
std::unique_ptr<xml::element>
make_element_for_patch (const diagnostic_info &diagnostic);
}
std::unique_ptr<xml::element>
-html_builder::make_element_for_metadata (const diagnostic_metadata &metadata)
+html_builder::make_element_for_metadata (const metadata &m)
{
auto span_metadata = make_span ("gcc-metadata");
- int cwe = metadata.get_cwe ();
+ int cwe = m.get_cwe ();
if (cwe)
{
pretty_printer pp;
(make_metadata_element (std::move (label), std::move (url)));
}
- for (unsigned idx = 0; idx < metadata.get_num_rules (); ++idx)
+ for (unsigned idx = 0; idx < m.get_num_rules (); ++idx)
{
- auto &rule = metadata.get_rule (idx);
+ auto &rule = m.get_rule (idx);
label_text label = label_text::take (rule.make_description ());
label_text url = label_text::take (rule.make_url ());
span_metadata->add_child
html_builder &b = dc.get_builder ();
{
- diagnostic_metadata metadata;
- metadata.add_cwe (415);
- auto element = b.make_element_for_metadata (metadata);
+ metadata m;
+ m.add_cwe (415);
+ auto element = b.make_element_for_metadata (m);
ASSERT_XML_PRINT_EQ
(*element,
"<span class=\"gcc-metadata\">"
}
{
- diagnostic_metadata metadata;
- diagnostic_metadata::precanned_rule rule ("MISC-42",
- "http://example.com");
- metadata.add_rule (rule);
- auto element = b.make_element_for_metadata (metadata);
+ metadata m;
+ metadata::precanned_rule rule ("MISC-42",
+ "http://example.com");
+ m.add_rule (rule);
+ auto element = b.make_element_for_metadata (m);
ASSERT_XML_PRINT_EQ
(*element,
"<span class=\"gcc-metadata\">"
#include "system.h"
#include "coretypes.h"
#include "diagnostic.h"
-#include "diagnostic-metadata.h"
+#include "diagnostics/metadata.h"
#include "diagnostics/digraphs.h"
#include "diagnostics/state-graphs.h"
#include "diagnostic-path.h"
- doesn't capture -Werror cleanly
- doesn't capture inlining information (can SARIF handle this?)
- doesn't capture macro expansion information (can SARIF handle this?).
- - doesn't capture any diagnostic_metadata::rules associated with
+ - doesn't capture any diagnostics::metadata::rules associated with
a diagnostic. */
class sarif_builder
diagnostic.metadata->maybe_add_sarif_properties (*result_obj);
- /* We don't yet support diagnostic_metadata::rule. */
+ /* We don't yet support diagnostics::metadata::rule. */
}
/* "level" property (SARIF v2.1.0 section 3.27.10). */
#include "diagnostic.h"
#include "diagnostic-color.h"
#include "diagnostic-url.h"
-#include "diagnostic-metadata.h"
+#include "diagnostics/metadata.h"
#include "diagnostic-path.h"
#include "diagnostic-client-data-hooks.h"
#include "diagnostic-diagram.h"
for (unsigned idx = 0; idx < diagnostic.metadata->get_num_rules (); idx++)
{
- const diagnostic_metadata::rule &rule
+ const diagnostics::metadata::rule &rule
= diagnostic.metadata->get_rule (idx);
if (char *desc = rule.make_description ())
{
bool
emit_diagnostic_valist_meta (diagnostic_t kind,
rich_location *richloc,
- const diagnostic_metadata *metadata,
+ const diagnostics::metadata *metadata,
diagnostic_option_id option_id,
const char *gmsgid, va_list *ap)
{
bool
warning_meta (rich_location *richloc,
- const diagnostic_metadata &metadata,
+ const diagnostics::metadata &metadata,
diagnostic_option_id option_id,
const char *gmsgid, ...)
{
/* Same as above, but with metadata. */
void
-error_meta (rich_location *richloc, const diagnostic_metadata &metadata,
+error_meta (rich_location *richloc, const diagnostics::metadata &metadata,
const char *gmsgid, ...)
{
gcc_assert (richloc);
#include "diagnostic.h"
#include "diagnostic-color.h"
#include "diagnostic-url.h"
-#include "diagnostic-metadata.h"
+#include "diagnostics/metadata.h"
#include "diagnostic-path.h"
#include "diagnostic-client-data-hooks.h"
#include "diagnostic-diagram.h"
diagnostic_context::
emit_diagnostic_with_group (diagnostic_t kind,
rich_location &richloc,
- const diagnostic_metadata *metadata,
+ const diagnostics::metadata *metadata,
diagnostic_option_id option_id,
const char *gmsgid, ...)
{
diagnostic_context::
emit_diagnostic_with_group_va (diagnostic_t kind,
rich_location &richloc,
- const diagnostic_metadata *metadata,
+ const diagnostics::metadata *metadata,
diagnostic_option_id option_id,
const char *gmsgid, va_list *ap)
{
and internal_error_no_backtrace, as documented and defined below. */
bool
diagnostic_context::diagnostic_impl (rich_location *richloc,
- const diagnostic_metadata *metadata,
+ const diagnostics::metadata *metadata,
diagnostic_option_id option_id,
const char *gmsgid,
va_list *ap, diagnostic_t kind)
defined below. */
bool
diagnostic_context::diagnostic_n_impl (rich_location *richloc,
- const diagnostic_metadata *metadata,
+ const diagnostics::metadata *metadata,
diagnostic_option_id option_id,
unsigned HOST_WIDE_INT n,
const char *singular_gmsgid,
/* An optional bundle of metadata associated with the diagnostic
(or NULL). */
- const diagnostic_metadata *metadata;
+ const diagnostics::metadata *metadata;
/* Auxiliary data for client. */
void *x_data;
bool emit_diagnostic_with_group (diagnostic_t kind,
rich_location &richloc,
- const diagnostic_metadata *metadata,
+ const diagnostics::metadata *metadata,
diagnostic_option_id option_id,
const char *gmsgid, ...)
ATTRIBUTE_GCC_DIAG(6,7);
bool emit_diagnostic_with_group_va (diagnostic_t kind,
rich_location &richloc,
- const diagnostic_metadata *metadata,
+ const diagnostics::metadata *metadata,
diagnostic_option_id option_id,
const char *gmsgid, va_list *ap)
ATTRIBUTE_GCC_DIAG(6,0);
return m_lang_mask;
}
- bool diagnostic_impl (rich_location *, const diagnostic_metadata *,
+ bool diagnostic_impl (rich_location *, const diagnostics::metadata *,
diagnostic_option_id, const char *,
va_list *, diagnostic_t) ATTRIBUTE_GCC_DIAG(5,0);
- bool diagnostic_n_impl (rich_location *, const diagnostic_metadata *,
+ bool diagnostic_n_impl (rich_location *, const diagnostics::metadata *,
diagnostic_option_id, unsigned HOST_WIDE_INT,
const char *, const char *, va_list *,
diagnostic_t) ATTRIBUTE_GCC_DIAG(7,0);
along with GCC; see the file COPYING3. If not see
<http://www.gnu.org/licenses/>. */
-#ifndef GCC_DIAGNOSTIC_METADATA_H
-#define GCC_DIAGNOSTIC_METADATA_H
+#ifndef GCC_DIAGNOSTICS_METADATA_H
+#define GCC_DIAGNOSTICS_METADATA_H
class sarif_object;
namespace diagnostics {
+
namespace digraphs {
class lazy_digraphs;
} // namespace digraphs
-} // namespace diagnostics
/* A bundle of additional metadata that can be associated with a
diagnostic.
Additionally, this provides a place to associate a diagnostic
with zero or more directed graphs. */
-class diagnostic_metadata
+class metadata
{
public:
/* Abstract base class for referencing a rule that has been violated,
const char *m_url;
};
- diagnostic_metadata () : m_cwe (0), m_lazy_digraphs (nullptr) {}
- virtual ~diagnostic_metadata () {}
+ metadata () : m_cwe (0), m_lazy_digraphs (nullptr) {}
+ virtual ~metadata () {}
/* Hook for SARIF output to allow for adding diagnostic-specific
properties to the result object's property bag. */
const rule &get_rule (unsigned idx) const { return *(m_rules[idx]); }
void
- set_lazy_digraphs (const diagnostics::digraphs::lazy_digraphs *lazy_digraphs)
+ set_lazy_digraphs (const digraphs::lazy_digraphs *lazy_digraphs)
{
m_lazy_digraphs = lazy_digraphs;
}
- const diagnostics::digraphs::lazy_digraphs *
+ const digraphs::lazy_digraphs *
get_lazy_digraphs () const
{
return m_lazy_digraphs;
/* An optional way to create directed graphs associated with the
diagnostic, for the sinks that support this (e.g. SARIF). */
- const diagnostics::digraphs::lazy_digraphs *m_lazy_digraphs;
+ const digraphs::lazy_digraphs *m_lazy_digraphs;
};
-#endif /* ! GCC_DIAGNOSTIC_METADATA_H */
+} // namespace diagnostics
+
+#endif /* ! GCC_DIAGNOSTICS_METADATA_H */
#include "diagnostic.h"
#include "diagnostic-color.h"
#include "diagnostic-url.h"
-#include "diagnostic-metadata.h"
+#include "diagnostics/metadata.h"
#include "diagnostic-path.h"
#include "diagnostic-client-data-hooks.h"
#include "diagnostic-format-sarif.h"
char *m_text;
};
-class impl_rule : public diagnostic_metadata::rule
+class impl_rule : public diagnostics::metadata::rule
{
public:
impl_rule (const char *title, const char *url)
enum diagnostic_level get_level () const { return m_level; }
rich_location *get_rich_location () { return &m_rich_loc; }
- const diagnostic_metadata *get_metadata () { return &m_metadata; }
+ const diagnostics::metadata *get_metadata () { return &m_metadata; }
void set_cwe (unsigned cwe_id)
{
enum diagnostic_level m_level;
impl_rich_location m_rich_loc;
const diagnostic_logical_location *m_logical_loc;
- diagnostic_metadata m_metadata;
+ diagnostics::metadata m_metadata;
prebuilt_digraphs m_graphs;
std::vector<std::unique_ptr<range_label>> m_labels;
std::vector<std::unique_ptr<impl_rule>> m_rules;
#include "rust-diagnostics.h"
#include "options.h"
-#include "diagnostic-metadata.h"
+#include "diagnostics/metadata.h"
static std::string
mformat_value ()
va_end (ap);
}
-class rust_error_code_rule : public diagnostic_metadata::rule
+class rust_error_code_rule : public diagnostics::metadata::rule
{
public:
rust_error_code_rule (const ErrorCode code) : m_code (code) {}
const std::string &errmsg)
{
rich_location gcc_loc (line_table, location);
- diagnostic_metadata m;
+ diagnostics::metadata m;
rust_error_code_rule rule (code);
m.add_rule (rule);
error_meta (&gcc_loc, m, "%s", errmsg.c_str ());
{
/* TODO: 'error_at' would like a non-'const' 'rich_location *'. */
rich_location &gcc_loc = const_cast<rich_location &> (location);
- diagnostic_metadata m;
+ diagnostics::metadata m;
rust_error_code_rule rule (code);
m.add_rule (rule);
error_meta (&gcc_loc, m, "%s", errmsg.c_str ());
rust_be_error_at (rich_location *richloc, const ErrorCode code,
const std::string &errmsg)
{
- diagnostic_metadata m;
+ diagnostics::metadata m;
rust_error_code_rule rule (code);
m.add_rule (rule);
error_meta (richloc, m, "%s", errmsg.c_str ());
bool
test_diagnostic_context::report (diagnostic_t kind,
rich_location &richloc,
- const diagnostic_metadata *metadata,
+ const diagnostics::metadata *metadata,
diagnostic_option_id option,
const char * fmt, ...)
{
bool
report (diagnostic_t kind,
rich_location &richloc,
- const diagnostic_metadata *metadata,
+ const diagnostics::metadata *metadata,
diagnostic_option_id option,
const char * fmt, ...) ATTRIBUTE_GCC_DIAG(6,7);
#include "fold-const.h"
#include "tree-pretty-print.h"
#include "diagnostic-color.h"
-#include "diagnostic-metadata.h"
+#include "diagnostics/metadata.h"
#include "tristate.h"
#include "bitmap.h"
#include "selftest.h"
#include "fold-const.h"
#include "tree-pretty-print.h"
#include "diagnostic-color.h"
-#include "diagnostic-metadata.h"
+#include "diagnostics/metadata.h"
#include "tristate.h"
#include "bitmap.h"
#include "selftest.h"
#include "fold-const.h"
#include "tree-pretty-print.h"
#include "diagnostic-color.h"
-#include "diagnostic-metadata.h"
+#include "diagnostics/metadata.h"
#include "tristate.h"
#include "bitmap.h"
#include "selftest.h"
#include "diagnostic.h"
#include "context.h"
#include "gcc-rich-location.h"
-#include "diagnostic-metadata.h"
+#include "diagnostics/metadata.h"
#include "diagnostics/digraphs.h"
#include "pass_manager.h"
};
gcc_rich_location rich_loc (loc);
- diagnostic_metadata meta;
+ diagnostics::metadata meta;
my_lazy_digraphs ldg;
meta.set_lazy_digraphs (&ldg);
error_meta (&rich_loc, meta,
-/* This plugin exercises diagnostic_metadata. */
+/* This plugin exercises diagnostics::metadata. */
#include "gcc-plugin.h"
#include "config.h"
#include "diagnostic.h"
#include "context.h"
#include "gcc-rich-location.h"
-#include "diagnostic-metadata.h"
+#include "diagnostics/metadata.h"
int plugin_is_GPL_compatible;
return call;
}
-/* Exercise diagnostic_metadata. */
+/* Exercise diagnostics::metadata. */
unsigned int
pass_test_metadata::execute (function *fun)
if (gcall *call = check_for_named_call (stmt, "gets", 1))
{
gcc_rich_location richloc (gimple_location (call));
- diagnostic_metadata m;
+ diagnostics::metadata m;
/* CWE-242: Use of Inherently Dangerous Function. */
m.add_cwe (242);
- /* Example of a diagnostic_metadata::rule. */
- diagnostic_metadata::precanned_rule
+ /* Example of a diagnostics::metadata::rule. */
+ diagnostics::metadata::precanned_rule
test_rule ("STR34-C", "https://example.com/");
m.add_rule (test_rule);
#include "plugin-version.h"
#include "diagnostic.h"
#include "diagnostic-path.h"
-#include "diagnostic-metadata.h"
+#include "diagnostics/metadata.h"
#include "context.h"
#include "print-tree.h"
#include "gcc-rich-location.h"
richloc.set_path (&path);
- diagnostic_metadata m;
+ diagnostics::metadata m;
m.add_cwe (415); /* CWE-415: Double Free. */
warning_meta (&richloc, m, 0,
richloc.set_path (&path);
- diagnostic_metadata m;
+ diagnostics::metadata m;
/* CWE-479: Signal Handler Use of a Non-reentrant Function. */
m.add_cwe (479);
thread_2, event_a_acquired);
richloc.set_path (&path);
- diagnostic_metadata m;
+ diagnostics::metadata m;
warning_meta (&richloc, m, 0,
"deadlock due to inconsistent lock acquisition order");
}