Tutorial part 3: logical locations

Let’s extend the previous example to add a logical location to the diagnostic.

First we create a diagnostic_logical_location representing a particular function:

const diagnostic_logical_location *logical_loc
  = diagnostic_manager_new_logical_location (diag_mgr,
                                             DIAGNOSTIC_LOGICAL_LOCATION_KIND_FUNCTION,
                                             NULL, /* parent */
                                             "foo",
                                             NULL,
                                             NULL);

In this simple example we specify that it is a function, and just give it a name (foo). For more complicated cases we can set up tree-like hierarchies of logical locations, set qualified names, “mangled” names, and so on; see diagnostic_manager_new_logical_location() for details.

Once we have diagnostic_logical_location we can associate it with a diagnostic with diagnostic_set_logical_location():

diagnostic_set_logical_location (d, logical_loc);

The logical location will be printed by text output sinks like this:

In function 'foo':

and will be captured in SARIF output.

Find out more

For more details on the above, see Logical locations. Otherwise the next part of the tutorial covers adding supplementary “notes” to a diagnostic.