Skip to content

Commit 3e2bea3

Browse files
authored
Merge pull request #4903 from tautschnig/memcpy-strings
Support OBJECT_SIZE over string constants
2 parents a47ec2d + 1ba3dfb commit 3e2bea3

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed

regression/cbmc/String8/main.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
int main()
2+
{
3+
_Bool branch;
4+
const char *str = 0;
5+
6+
if(branch)
7+
{
8+
str = "foo";
9+
}
10+
else
11+
{
12+
str = "bar";
13+
}
14+
15+
char a = str[2];
16+
__CPROVER_assert(a == 'o' || a == 'r', "");
17+
18+
return 0;
19+
}

regression/cbmc/String8/test.desc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE broken-smt-backend
2+
main.c
3+
--pointer-check --bounds-check
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring

src/solvers/flattening/bv_pointers.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,7 @@ void bv_pointerst::do_postponed(
768768
{
769769
const exprt &expr=*it;
770770

771-
if(expr.id() != ID_symbol)
771+
if(expr.id() != ID_symbol && expr.id() != ID_string_constant)
772772
continue;
773773

774774
const auto size_expr = size_of_expr(expr.type(), ns);

src/solvers/smt2/smt2_conv.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,8 @@ void smt2_convt::define_object_size(
220220
numeric_cast<mp_integer>(size_expr.value_or(nil_exprt()));
221221

222222
if(
223-
o.id() != ID_symbol || !size_expr.has_value() || !object_size.has_value())
223+
(o.id() != ID_symbol && o.id() != ID_string_constant) ||
224+
!size_expr.has_value() || !object_size.has_value())
224225
{
225226
++number;
226227
continue;

0 commit comments

Comments
 (0)