+2020-02-26 David Malcolm <dmalcolm@redhat.com>
+
+ PR analyzer/93950
+ * diagnostic-manager.cc
+ (diagnostic_manager::prune_for_sm_diagnostic): Assert that var is
+ either NULL or not a constant. When updating var, bulletproof
+ against constant values.
+
2020-02-26 David Malcolm <dmalcolm@redhat.com>
PR analyzer/93947
else
log ("considering event %i", idx);
}
+ gcc_assert (var == NULL || !CONSTANT_CLASS_P (var));
switch (base_event->m_kind)
{
default:
log ("event %i: switching var of interest from %qE to %qE",
idx, var, state_change->m_origin);
var = state_change->m_origin;
+ if (var && CONSTANT_CLASS_P (var))
+ {
+ log ("new var is a constant; setting var to NULL");
+ var = NULL_TREE;
+ }
}
log ("event %i: switching state of interest from %qs to %qs",
idx, sm->get_state_name (state_change->m_to),
var = caller_var;
if (expr.param_p ())
event->record_critical_state (var, state);
+ if (var && CONSTANT_CLASS_P (var))
+ {
+ log ("new var is a constant; setting var to NULL");
+ var = NULL_TREE;
+ }
}
}
break;
var = callee_var;
if (expr.return_value_p ())
event->record_critical_state (var, state);
+ if (var && CONSTANT_CLASS_P (var))
+ {
+ log ("new var is a constant; setting var to NULL");
+ var = NULL_TREE;
+ }
}
}
}
--- /dev/null
+// { dg-do compile { target c++11 } }
+
+struct d
+{
+ struct e
+ {
+ int f;
+ int *g;
+ };
+ void h (e * i)
+ {
+ void *j = nullptr; // { dg-bogus "NULL" "" { xfail *-*-* } }
+ // TODO(xfail): we report "'i' is NULL" above, which is the wrong location
+
+ i->f = *i->g; // { dg-warning "dereference of NULL 'i'" }
+ }
+ virtual void c (int, int)
+ {
+ int *j = nullptr;
+ h (nullptr);
+ }
+};
+
+void
+foo ()
+{
+ d ();
+}