From 9b55e446bb8df22c08a023b14d56dbb57259fe7d Mon Sep 17 00:00:00 2001 From: David Malcolm Date: Tue, 30 Jun 2020 16:30:54 -0400 Subject: [PATCH 265/315] FIXME: fix [0] of a STRING_CST --- gcc/analyzer/region-model2.cc | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/gcc/analyzer/region-model2.cc b/gcc/analyzer/region-model2.cc index c5d8de45537..a3c15b4ef2f 100644 --- a/gcc/analyzer/region-model2.cc +++ b/gcc/analyzer/region-model2.cc @@ -5758,6 +5758,21 @@ region_model2::get_store_value (const region2 *reg) return m_mgr->get_or_create_cast (reg->get_type (), char_sval); } + /* Special-case: read the initial char of a STRING_CST. */ + // FIXME: but only if the cast is to a char? + if (const cast_region2 *cast_reg = reg->dyn_cast_cast_region2 ()) + if (const string_region2 *str_reg + = cast_reg->get_original_region ()->dyn_cast_string_region2 ()) + if (reg->get_type ()) // FIXME + { + tree string_cst = str_reg->get_string_cst (); + tree byte_offset_cst = build_int_cst (integer_type_node, 0); + if (const svalue2 *char_sval + = maybe_get_char_from_string_cst (string_cst, byte_offset_cst, + m_mgr)) + return m_mgr->get_or_create_cast (reg->get_type (), char_sval); + } + /* FIXME: not if touched by symbolic value; handled in binding_cluster2::get_any_binding. */ return m_mgr->get_or_create_initial_value (reg); -- 2.26.2