analyzer: fix ICE copying struct [PR 94816]
authorDavid Malcolm <dmalcolm@redhat.com>
Tue, 28 Apr 2020 14:52:45 +0000 (10:52 -0400)
committerDavid Malcolm <dmalcolm@redhat.com>
Tue, 28 Apr 2020 17:26:22 +0000 (13:26 -0400)
commit5eae0ac76dcb6aac1d1d6c4edd8852e0035792e4
treeba5b675ec69939002165d48396d71a2b871701f4
parent0e8e1a6d97cc44d47992e40198490f780fbbfd5a
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.
gcc/analyzer/ChangeLog
gcc/analyzer/engine.cc
gcc/analyzer/region-model.cc
gcc/analyzer/region-model.h
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/analyzer/pr94816.C [new file with mode: 0644]