Skip to content

Commit e6f659d

Browse files
authored
Merge pull request #4241 from tautschnig/cex-string
Counterexamples: show strings, not address-of-character
2 parents 628f776 + 6d31679 commit e6f659d

File tree

4 files changed

+35
-0
lines changed

4 files changed

+35
-0
lines changed

regression/cbmc/trace-strings/main.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
int main()
2+
{
3+
char *c = "abc";
4+
++c;
5+
assert(0);
6+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CORE
2+
main.c
3+
--trace
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
c="abc"
7+
c=\{ 'b', 'c', 0 \}
8+
^VERIFICATION FAILED$
9+
--
10+
^warning: ignoring

src/solvers/flattening/pointer_logic.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,20 @@ exprt pointer_logict::pointer_expr(
104104
// https://gcc.gnu.org/onlinedocs/gcc-4.8.0/gcc/Pointer-Arith.html
105105
if(subtype.id() == ID_empty)
106106
subtype = char_type();
107+
if(object_expr.id() == ID_string_constant)
108+
{
109+
subtype = object_expr.type();
110+
111+
// a string constant must be array-typed with fixed size
112+
const array_typet &array_type = to_array_type(object_expr.type());
113+
mp_integer array_size =
114+
numeric_cast_v<mp_integer>(to_constant_expr(array_type.size()));
115+
if(array_size > pointer.offset)
116+
{
117+
to_array_type(subtype).size() =
118+
from_integer(array_size - pointer.offset, array_type.size().type());
119+
}
120+
}
107121
exprt deep_object =
108122
get_subexpression_at_offset(object_expr, pointer.offset, subtype, ns);
109123
CHECK_RETURN(deep_object.is_not_nil());

src/util/simplify_expr.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Author: Daniel Kroening, [email protected]
2626
#include "rational_tools.h"
2727
#include "simplify_utils.h"
2828
#include "std_expr.h"
29+
#include "string_constant.h"
2930
#include "string_expr.h"
3031
#include "symbol.h"
3132
#include "type_eq.h"
@@ -1795,6 +1796,10 @@ optionalt<std::string> simplify_exprt::expr2bits(
17951796
constant_exprt(value, to_c_enum_type(type).subtype()), little_endian);
17961797
}
17971798
}
1799+
else if(expr.id() == ID_string_constant)
1800+
{
1801+
return expr2bits(to_string_constant(expr).to_array_expr(), little_endian);
1802+
}
17981803
else if(expr.id()==ID_union)
17991804
{
18001805
return expr2bits(to_union_expr(expr).op(), little_endian);

0 commit comments

Comments
 (0)