analyzer: fix ICE on failed casts [PR 93777]
authorDavid Malcolm <dmalcolm@redhat.com>
Mon, 17 Feb 2020 22:37:52 +0000 (17:37 -0500)
committerDavid Malcolm <dmalcolm@redhat.com>
Tue, 18 Feb 2020 13:17:43 +0000 (08:17 -0500)
commit4f40164a9322105012e9070eebd57ba80c69b873
tree79427a7450ddd0c840b14ea072e7f7818459067e
parent2e6233935c77b56a68e939c629702f960b8e6fb2
analyzer: fix ICE on failed casts [PR 93777]

PR analyzer/93777 reports ICEs in a Fortran and C++ case involving
a cast of a NULL pointer to a REFERENCE_TYPE.

In both cases the call to build_cast fails and returns a NULL type, but
region_model::maybe_cast_1 asserts that a non-NULL type was returned.

This patch fixes the ICEs by converting the assertion to a conditional.

gcc/analyzer/ChangeLog:
PR analyzer/93777
* region-model.cc (region_model::maybe_cast_1): Replace assertion
that build_cast returns non-NULL with a conditional, falling
through to the logic which returns a new unknown value of the
desired type if it fails.

gcc/testsuite/ChangeLog:
PR analyzer/93777
* g++.dg/analyzer/pr93777.C: New test.
* gfortran.dg/analyzer/pr93777.f90: New test.
gcc/analyzer/ChangeLog
gcc/analyzer/region-model.cc
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/analyzer/pr93777.C [new file with mode: 0644]
gcc/testsuite/gfortran.dg/analyzer/pr93777.f90 [new file with mode: 0644]