Skip to content

Counterexamples: show strings, not address-of-character #4241

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions regression/cbmc/trace-strings/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
int main()
{
char *c = "abc";
++c;
assert(0);
}
10 changes: 10 additions & 0 deletions regression/cbmc/trace-strings/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
CORE
main.c
--trace
^EXIT=10$
^SIGNAL=0$
c="abc"
c=\{ 'b', 'c', 0 \}
^VERIFICATION FAILED$
--
^warning: ignoring
14 changes: 14 additions & 0 deletions src/solvers/flattening/pointer_logic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,20 @@ exprt pointer_logict::pointer_expr(
// https://gcc.gnu.org/onlinedocs/gcc-4.8.0/gcc/Pointer-Arith.html
if(subtype.id() == ID_empty)
subtype = char_type();
if(object_expr.id() == ID_string_constant)
{
subtype = object_expr.type();

// a string constant must be array-typed with fixed size
const array_typet &array_type = to_array_type(object_expr.type());
mp_integer array_size =
numeric_cast_v<mp_integer>(to_constant_expr(array_type.size()));
if(array_size > pointer.offset)
{
to_array_type(subtype).size() =
from_integer(array_size - pointer.offset, array_type.size().type());
}
}
exprt deep_object =
get_subexpression_at_offset(object_expr, pointer.offset, subtype, ns);
CHECK_RETURN(deep_object.is_not_nil());
Expand Down
5 changes: 5 additions & 0 deletions src/util/simplify_expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Author: Daniel Kroening, [email protected]
#include "rational_tools.h"
#include "simplify_utils.h"
#include "std_expr.h"
#include "string_constant.h"
#include "string_expr.h"
#include "symbol.h"
#include "type_eq.h"
Expand Down Expand Up @@ -1795,6 +1796,10 @@ optionalt<std::string> simplify_exprt::expr2bits(
constant_exprt(value, to_c_enum_type(type).subtype()), little_endian);
}
}
else if(expr.id() == ID_string_constant)
{
return expr2bits(to_string_constant(expr).to_array_expr(), little_endian);
}
else if(expr.id()==ID_union)
{
return expr2bits(to_union_expr(expr).op(), little_endian);
Expand Down