public:
path_builder (const exploded_graph &eg,
const exploded_path &epath,
- const feasibility_problem *problem)
+ const feasibility_problem *problem,
+ const saved_diagnostic &sd)
: m_eg (eg),
m_diag_enode (epath.get_final_enode ()),
+ m_sd (sd),
m_reachability (eg, m_diag_enode),
m_feasibility_problem (problem)
{}
const exploded_node *get_diag_node () const { return m_diag_enode; }
+ pending_diagnostic *get_pending_diagnostic () const
+ {
+ return m_sd.m_d;
+ }
+
bool reachable_from_p (const exploded_node *src_enode) const
{
return m_reachability.reachable_from_p (src_enode);
/* The enode where the diagnostic occurs. */
const exploded_node *m_diag_enode;
+ const saved_diagnostic &m_sd;
+
/* Precompute all enodes from which the diagnostic is reachable. */
enode_reachability m_reachability;
pretty_printer *pp = global_dc->printer->clone ();
/* Precompute all enodes from which the diagnostic is reachable. */
- path_builder pb (eg, epath, sd.get_feasibility_problem ());
+ path_builder pb (eg, epath, sd.get_feasibility_problem (), sd);
/* This is the diagnostic_path subclass that will be built for
the diagnostic. */
{
gcc_assert (eedge.m_sedge);
+ /* Give diagnostics an opportunity to override this function. */
+ pending_diagnostic *pd = pb.get_pending_diagnostic ();
+ if (pd->maybe_add_custom_events_for_superedge (eedge, emission_path))
+ return;
+
/* Don't add events for insignificant edges at verbosity levels below 3. */
if (m_verbosity < 3)
if (!significant_edge_p (pb, eedge))
class stale_jmp_buf : public pending_diagnostic_subclass<dump_path_diagnostic>
{
public:
- stale_jmp_buf (const gcall *setjmp_call, const gcall *longjmp_call)
- : m_setjmp_call (setjmp_call), m_longjmp_call (longjmp_call)
+ stale_jmp_buf (const gcall *setjmp_call, const gcall *longjmp_call,
+ const program_point &setjmp_point)
+ : m_setjmp_call (setjmp_call), m_longjmp_call (longjmp_call),
+ m_setjmp_point (setjmp_point), m_stack_pop_event (NULL)
{}
bool emit (rich_location *richloc) FINAL OVERRIDE
&& m_longjmp_call == other.m_longjmp_call);
}
+ bool
+ maybe_add_custom_events_for_superedge (const exploded_edge &eedge,
+ checker_path *emission_path)
+ FINAL OVERRIDE
+ {
+ /* Detect exactly when the stack first becomes invalid,
+ and issue an event then. */
+ if (m_stack_pop_event)
+ return false;
+ const exploded_node *src_node = eedge.m_src;
+ const program_point &src_point = src_node->get_point ();
+ const exploded_node *dst_node = eedge.m_dest;
+ const program_point &dst_point = dst_node->get_point ();
+ if (valid_longjmp_stack_p (src_point, m_setjmp_point)
+ && !valid_longjmp_stack_p (dst_point, m_setjmp_point))
+ {
+ /* Compare with diagnostic_manager::add_events_for_superedge. */
+ const int src_stack_depth = src_point.get_stack_depth ();
+ m_stack_pop_event = new custom_event
+ (src_point.get_location (),
+ src_point.get_fndecl (),
+ src_stack_depth,
+ "stack frame is popped here, invalidating saved environment");
+ emission_path->add_event (m_stack_pop_event);
+ return false;
+ }
+ return false;
+ }
+
+ label_text describe_final_event (const evdesc::final_event &ev)
+ {
+ if (m_stack_pop_event)
+ return ev.formatted_print
+ ("%qs called after enclosing function of %qs returned at %@",
+ get_user_facing_name (m_longjmp_call),
+ get_user_facing_name (m_setjmp_call),
+ m_stack_pop_event->get_id_ptr ());
+ else
+ return ev.formatted_print
+ ("%qs called after enclosing function of %qs has returned",
+ get_user_facing_name (m_longjmp_call),
+ get_user_facing_name (m_setjmp_call));;
+ }
+
+
private:
const gcall *m_setjmp_call;
const gcall *m_longjmp_call;
+ program_point m_setjmp_point;
+ custom_event *m_stack_pop_event;
};
/* Handle LONGJMP_CALL, a call to longjmp or siglongjmp.
/* Verify that the setjmp's call_stack hasn't been popped. */
if (!valid_longjmp_stack_p (longjmp_point, setjmp_point))
{
- ctxt->warn (new stale_jmp_buf (setjmp_call, longjmp_call));
+ ctxt->warn (new stale_jmp_buf (setjmp_call, longjmp_call, setjmp_point));
return;
}
}
/* End of precision-of-wording vfuncs. */
+
+ /* Vfunc for extending/overriding creation of the events for an
+ exploded_edge that corresponds to a superedge, allowing for custom
+ events to be created that are pertinent to a particular
+ pending_diagnostic subclass.
+
+ For example, the -Wanalyzer-stale-setjmp-buffer diagnostic adds a
+ custom event showing when the pertinent stack frame is popped
+ (and thus the point at which the jmp_buf becomes invalid). */
+
+ virtual bool maybe_add_custom_events_for_superedge (const exploded_edge &,
+ checker_path *)
+ {
+ return false;
+ }
};
/* A template to make it easier to make subclasses of pending_diagnostic.