analyzer: fix ICE on unknown index in CONSTRUCTOR [PR96860]
authorDavid Malcolm <dmalcolm@redhat.com>
Mon, 31 Aug 2020 13:00:23 +0000 (09:00 -0400)
committerDavid Malcolm <dmalcolm@redhat.com>
Mon, 31 Aug 2020 22:28:59 +0000 (18:28 -0400)
commit18056e45db1c75aa209fa9a756395ddceb867a88
tree0a2207a90419a73af0bcf0086cb1c3a6a45d35a7
parent73a2b8dd17dbc02c0c7e6286e90f17833aa50906
analyzer: fix ICE on unknown index in CONSTRUCTOR [PR96860]

PR analyzer/96860 reports an ICE inside CONSTRUCTOR-handling with
--param analyzer-max-svalue-depth=0 when attempting to build a
binding_map for the CONSTRUCTOR's values.

The issue is that when handling (index, value) pairs for initializing
an array, the index values for the elements exceeds the svalue
complexity limit, and the index is thus treated as unknown, leading to
a symbolic rather than concrete offset for each array element.

This patch updates the CONSTRUCTOR-handling code so that it can
fail, returning an unknown value for the overall value of the
constructor for this case, fixing the ICE.

gcc/analyzer/ChangeLog:
PR analyzer/96860
* region.cc (decl_region::get_svalue_for_constructor): Support
apply_ctor_to_region failing.
* store.cc (binding_map::apply_ctor_to_region): Add failure
handling.
(binding_map::apply_ctor_val_to_range): Likewise.
(binding_map::apply_ctor_pair_to_child_region): Likewise.  Replace
assertion that child_base_offset is not symbolic with error
handling.
* store.h (binding_map::apply_ctor_to_region): Convert return type
from void to bool.
(binding_map::apply_ctor_val_to_range): Likewise.
(binding_map::apply_ctor_pair_to_child_region): Likewise.

gcc/testsuite/ChangeLog:
PR analyzer/96860
* gcc.dg/analyzer/pr96860-1.c: New test.
* gcc.dg/analyzer/pr96860-2.c: New test.
gcc/analyzer/region.cc
gcc/analyzer/store.cc
gcc/analyzer/store.h
gcc/testsuite/gcc.dg/analyzer/pr96860-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/analyzer/pr96860-2.c [new file with mode: 0644]