analyzer: fix ICE with -fsanitize=undefined [PR98293]
authorDavid Malcolm <dmalcolm@redhat.com>
Tue, 5 Jan 2021 00:20:32 +0000 (19:20 -0500)
committerDavid Malcolm <dmalcolm@redhat.com>
Tue, 5 Jan 2021 00:20:32 +0000 (19:20 -0500)
commit15af33a88065f983181550fc53821f1c6e14c5c7
tree8dc2bf2647da05507089886acd6f04a41390e253
parent7e73f511573b3656c57f33c079e9bd1d70aaa621
analyzer: fix ICE with -fsanitize=undefined [PR98293]

-fsanitize=undefined with calls to nonnull functions
creates struct __ubsan_nonnull_arg_data instances
with CONSTRUCTORs for RECORD_TYPEs with NULL index values.
The analyzer was mistakenly using INTEGER_CST for these
fields, leading to ICEs.

Fix the issue by iterating through the fields in the type
for such cases, imitating similar logic in varasm.c's
output_constructor.

gcc/analyzer/ChangeLog:
PR analyzer/98293
* store.cc (binding_map::apply_ctor_to_region): When "index" is
NULL, iterate through the fields for RECORD_TYPEs, rather than
creating an INTEGER_CST index.

gcc/testsuite/ChangeLog:
PR analyzer/98293
* gcc.dg/analyzer/pr98293.c: New test.
gcc/analyzer/store.cc
gcc/testsuite/gcc.dg/analyzer/pr98293.c [new file with mode: 0644]