diff options
author | David Malcolm <dmalcolm@redhat.com> | 2020-04-28 10:52:45 -0400 |
---|---|---|
committer | David Malcolm <dmalcolm@redhat.com> | 2020-04-28 13:26:22 -0400 |
commit | 5eae0ac76dcb6aac1d1d6c4edd8852e0035792e4 (patch) | |
tree | ba5b675ec69939002165d48396d71a2b871701f4 /gcc/analyzer | |
parent | 0e8e1a6d97cc44d47992e40198490f780fbbfd5a (diff) | |
download | gcc-5eae0ac76dcb6aac1d1d6c4edd8852e0035792e4.zip gcc-5eae0ac76dcb6aac1d1d6c4edd8852e0035792e4.tar.gz gcc-5eae0ac76dcb6aac1d1d6c4edd8852e0035792e4.tar.bz2 |
analyzer: fix ICE copying struct [PR 94816]
PR analyzer/94816 reports an ICE when attempting to copy a struct
containing a field for which add_region_for_type for fails (on
an OFFSET_TYPE): the region for the src field comes from
make_region_for_unexpected_tree_code which gives it a NULL type, and
then the copy calls add_region_for_type which unconditionally
dereferences the NULL type.
This patch fixes the ICE by checking for NULL types in
add_region_for_type.
gcc/analyzer/ChangeLog:
PR analyzer/94816
* engine.cc (impl_region_model_context::on_unexpected_tree_code):
Handle NULL tree.
* region-model.cc (region_model::add_region_for_type): Handle
NULL type.
* region-model.h
(test_region_model_context::on_unexpected_tree_code): Handle NULL
tree.
gcc/testsuite/ChangeLog:
PR analyzer/94816
* g++.dg/analyzer/pr94816.C: New test.
Diffstat (limited to 'gcc/analyzer')
-rw-r--r-- | gcc/analyzer/ChangeLog | 11 | ||||
-rw-r--r-- | gcc/analyzer/engine.cc | 2 | ||||
-rw-r--r-- | gcc/analyzer/region-model.cc | 9 | ||||
-rw-r--r-- | gcc/analyzer/region-model.h | 2 |
4 files changed, 19 insertions, 5 deletions
diff --git a/gcc/analyzer/ChangeLog b/gcc/analyzer/ChangeLog index 3c8f458..5cd7363 100644 --- a/gcc/analyzer/ChangeLog +++ b/gcc/analyzer/ChangeLog @@ -1,5 +1,16 @@ 2020-04-28 David Malcolm <dmalcolm@redhat.com> + PR analyzer/94816 + * engine.cc (impl_region_model_context::on_unexpected_tree_code): + Handle NULL tree. + * region-model.cc (region_model::add_region_for_type): Handle + NULL type. + * region-model.h + (test_region_model_context::on_unexpected_tree_code): Handle NULL + tree. + +2020-04-28 David Malcolm <dmalcolm@redhat.com> + PR analyzer/94447 PR analyzer/94639 PR analyzer/94732 diff --git a/gcc/analyzer/engine.cc b/gcc/analyzer/engine.cc index 880e70f..c73d493 100644 --- a/gcc/analyzer/engine.cc +++ b/gcc/analyzer/engine.cc @@ -699,7 +699,7 @@ impl_region_model_context::on_unexpected_tree_code (tree t, logger * const logger = get_logger (); if (logger) logger->log ("unhandled tree code: %qs in %qs at %s:%i", - get_tree_code_name (TREE_CODE (t)), + t ? get_tree_code_name (TREE_CODE (t)) : "(null)", loc.get_impl_location ().m_function, loc.get_impl_location ().m_file, loc.get_impl_location ().m_line); diff --git a/gcc/analyzer/region-model.cc b/gcc/analyzer/region-model.cc index 22049a3..0794be9 100644 --- a/gcc/analyzer/region-model.cc +++ b/gcc/analyzer/region-model.cc @@ -6448,10 +6448,13 @@ region_id region_model::add_region_for_type (region_id parent_rid, tree type, region_model_context *ctxt) { - gcc_assert (TYPE_P (type)); + if (type) + { + gcc_assert (TYPE_P (type)); - if (region *new_region = make_region_for_type (parent_rid, type)) - return add_region (new_region); + if (region *new_region = make_region_for_type (parent_rid, type)) + return add_region (new_region); + } /* If we can't handle TYPE, return a placeholder region, and stop exploring this path. */ diff --git a/gcc/analyzer/region-model.h b/gcc/analyzer/region-model.h index ad3dd1d..6d427c4 100644 --- a/gcc/analyzer/region-model.h +++ b/gcc/analyzer/region-model.h @@ -2205,7 +2205,7 @@ public: FINAL OVERRIDE { internal_error ("unhandled tree code: %qs", - get_tree_code_name (TREE_CODE (t))); + t ? get_tree_code_name (TREE_CODE (t)) : "(null)"); } private: |