gimple-simulate: prise en charge initialisation chaînes de caractères

This commit is contained in:
Mikael Morin 2025-10-09 12:15:25 +02:00
parent 0c0615355a
commit 364d903a19
1 changed files with 26 additions and 0 deletions

View File

@ -2022,6 +2022,18 @@ simul_valueize (tree t)
}
static void
set_cst_array_elem_at (data_value &result, tree elt_type, int index, int value)
{
unsigned elt_size = get_constant_type_size (elt_type);
wide_int val = wi::uhwi (value, elt_size);
data_value elt_val (elt_size);
elt_val.set_known (val);
result.set_at (elt_val, index * elt_size);
}
/* Evaluate the expression EXPR using the values currently stored in
accessible variables and allocated storages and return the resulting value.
*/
@ -2157,6 +2169,20 @@ simul_scope::evaluate (tree expr) const
return result;
}
case STRING_CST:
{
tree expr_type = TREE_TYPE (expr);
data_value result (expr_type);
tree elt_type = TREE_TYPE (expr_type);
int len = TREE_STRING_LENGTH (expr);
const char *str = TREE_STRING_POINTER (expr);
for (int i = 0; i < len; ++i)
set_cst_array_elem_at (result, elt_type, i, str[i]);
set_cst_array_elem_at (result, elt_type, len, 0);
return result;
}
case CONSTRUCTOR:
return evaluate_constructor (expr);