gcc/analyzer/ChangeLog:
PR analyzer/109366
* region-model-manager.cc
(region_model_manager::maybe_fold_sub_svalue): Sub-values of zero
constants are zero.
gcc/testsuite/ChangeLog:
PR analyzer/109366
* g++.dg/analyzer/unique_ptr-1.C: New test.
* g++.dg/analyzer/unique_ptr-2.C: New test.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
if (!parent_svalue->can_have_associated_state_p ())
return get_or_create_unknown_svalue (type);
+ /* If we have a subvalue of a zero constant, it's zero. */
+ if (tree cst = parent_svalue->maybe_get_constant ())
+ if (TREE_CODE (cst) == INTEGER_CST)
+ if (zerop (cst))
+ return get_or_create_cast (type, parent_svalue);
+
/* If we have a subregion of a zero-fill, it's zero. */
if (const unaryop_svalue *unary
= parent_svalue->dyn_cast_unaryop_svalue ())
--- /dev/null
+// Verify that we complain about trivial uses of NULL unique_ptr.
+
+// { dg-do compile { target c++11 } }
+
+#include <memory>
+
+struct A {int x; int y;};
+
+int main() {
+ std::unique_ptr<A> a;
+ a->x = 12; // { dg-warning "dereference of NULL" }
+ return 0;
+}
--- /dev/null
+// { dg-do compile { target c++11 } }
+// { dg-additional-options "-Wno-analyzer-too-complex" } */
+
+#include <memory>
+
+struct A {int x; int y;};
+
+extern std::unique_ptr<A> make_ptr ();
+
+int test (int flag) {
+ std::unique_ptr<A> a;
+ if (flag)
+ a = make_ptr ();
+ a->x = 12; // { dg-warning "dereference of NULL" "" { xfail *-*-*} }
+ // TODO: this is failing due to "too complex" warnings
+ return 0;
+}