aboutsummaryrefslogtreecommitdiff
path: root/gcc/analyzer
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2023-08-24 10:24:40 -0400
committerDavid Malcolm <dmalcolm@redhat.com>2023-08-24 10:24:40 -0400
commit46cb27e56f36f23cb277f8a5beae05235af05768 (patch)
tree0c194baeb3f0a960daba3db40e351cfff99a19cb /gcc/analyzer
parentd99d73c77d1e9cca5938134b4e6e068945cf50b1 (diff)
downloadgcc-46cb27e56f36f23cb277f8a5beae05235af05768.zip
gcc-46cb27e56f36f23cb277f8a5beae05235af05768.tar.gz
gcc-46cb27e56f36f23cb277f8a5beae05235af05768.tar.bz2
analyzer: handle INIT_VAL(ELEMENT_REG(STRING_REG), CONSTANT_SVAL) [PR105899]
gcc/analyzer/ChangeLog: PR analyzer/105899 * region-model-manager.cc (region_model_manager::get_or_create_initial_value): Simplify INIT_VAL(ELEMENT_REG(STRING_REG), CONSTANT_SVAL) to CONSTANT_SVAL(STRING[N]). Signed-off-by: David Malcolm <dmalcolm@redhat.com>
Diffstat (limited to 'gcc/analyzer')
-rw-r--r--gcc/analyzer/region-model-manager.cc19
1 files changed, 19 insertions, 0 deletions
diff --git a/gcc/analyzer/region-model-manager.cc b/gcc/analyzer/region-model-manager.cc
index 65b7190..2224687 100644
--- a/gcc/analyzer/region-model-manager.cc
+++ b/gcc/analyzer/region-model-manager.cc
@@ -310,6 +310,25 @@ region_model_manager::get_or_create_initial_value (const region *reg,
get_or_create_initial_value (original_reg));
}
+ /* Simplify:
+ INIT_VAL(ELEMENT_REG(STRING_REG), CONSTANT_SVAL)
+ to:
+ CONSTANT_SVAL(STRING[N]). */
+ if (const element_region *element_reg = reg->dyn_cast_element_region ())
+ if (tree cst_idx = element_reg->get_index ()->maybe_get_constant ())
+ if (const string_region *string_reg
+ = element_reg->get_parent_region ()->dyn_cast_string_region ())
+ if (tree_fits_shwi_p (cst_idx))
+ {
+ HOST_WIDE_INT idx = tree_to_shwi (cst_idx);
+ tree string_cst = string_reg->get_string_cst ();
+ if (idx >= 0 && idx <= TREE_STRING_LENGTH (string_cst))
+ {
+ int ch = TREE_STRING_POINTER (string_cst)[idx];
+ return get_or_create_int_cst (reg->get_type (), ch);
+ }
+ }
+
/* INIT_VAL (*UNKNOWN_PTR) -> UNKNOWN_VAL. */
if (reg->symbolic_for_unknown_ptr_p ())
return get_or_create_unknown_svalue (reg->get_type ());