aboutsummaryrefslogtreecommitdiff
path: root/gcc/analyzer/constraint-manager.cc
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2021-09-08 14:37:19 -0400
committerDavid Malcolm <dmalcolm@redhat.com>2021-09-08 14:37:19 -0400
commite66b9f6779f46433b0e2c093b58403604ed131cc (patch)
treeab637db2e7048d40545e4be1964f4334b80eff19 /gcc/analyzer/constraint-manager.cc
parent716a5836928ee6d8fb884d9a2fbc1b1386ec8994 (diff)
downloadgcc-e66b9f6779f46433b0e2c093b58403604ed131cc.zip
gcc-e66b9f6779f46433b0e2c093b58403604ed131cc.tar.gz
gcc-e66b9f6779f46433b0e2c093b58403604ed131cc.tar.bz2
analyzer: fix ICE when discarding result of realloc [PR102225]
gcc/analyzer/ChangeLog: PR analyzer/102225 * analyzer.h (compat_types_p): New decl. * constraint-manager.cc (constraint_manager::get_or_add_equiv_class): Guard against NULL type when checking for pointer types. * region-model-impl-calls.cc (region_model::impl_call_realloc): Guard against NULL lhs type/region. Guard against the size value not being of a compatible type for dynamic extents. * region-model.cc (compat_types_p): Make non-static. gcc/testsuite/ChangeLog: PR analyzer/102225 * gcc.dg/analyzer/realloc-1.c (test_10): New. * gcc.dg/analyzer/torture/pr102225.c: New test.
Diffstat (limited to 'gcc/analyzer/constraint-manager.cc')
-rw-r--r--gcc/analyzer/constraint-manager.cc9
1 files changed, 5 insertions, 4 deletions
diff --git a/gcc/analyzer/constraint-manager.cc b/gcc/analyzer/constraint-manager.cc
index dc65c8d..6df23fb 100644
--- a/gcc/analyzer/constraint-manager.cc
+++ b/gcc/analyzer/constraint-manager.cc
@@ -2088,10 +2088,11 @@ constraint_manager::get_or_add_equiv_class (const svalue *sval)
/* Convert all NULL pointers to (void *) to avoid state explosions
involving all of the various (foo *)NULL vs (bar *)NULL. */
- if (POINTER_TYPE_P (sval->get_type ()))
- if (tree cst = sval->maybe_get_constant ())
- if (zerop (cst))
- sval = m_mgr->get_or_create_constant_svalue (null_pointer_node);
+ if (sval->get_type ())
+ if (POINTER_TYPE_P (sval->get_type ()))
+ if (tree cst = sval->maybe_get_constant ())
+ if (zerop (cst))
+ sval = m_mgr->get_or_create_constant_svalue (null_pointer_node);
/* Try svalue match. */
if (get_equiv_class_by_svalue (sval, &result))