Skip to content

Properly handle void* #955

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 2 commits into from
May 23, 2017
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
12 changes: 12 additions & 0 deletions regression/cbmc/void_pointer1/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
char buffer[2];
int length = 2;

void func(void* buf, int len)
{
while( len-- )
*(char *)buf++;
}

void main(){
func(buffer,length);
}
8 changes: 8 additions & 0 deletions regression/cbmc/void_pointer1/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CORE
main.c
--pointer-check
^EXIT=0$
^SIGNAL=0$
^VERIFICATION SUCCESSFUL$
--
^warning: ignoring
12 changes: 12 additions & 0 deletions regression/cbmc/void_pointer2/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
char buffer[2];
int length = 2;

void func(void* buf, int len)
{
while( len-- )
*(char *)buf++;
}

void main(){
func(buffer,length);
}
8 changes: 8 additions & 0 deletions regression/cbmc/void_pointer2/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CORE
main.c
--pointer-check --no-simplify --unwind 3
^EXIT=0$
^SIGNAL=0$
^VERIFICATION SUCCESSFUL$
--
^warning: ignoring
3 changes: 2 additions & 1 deletion src/analyses/goto_check.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1238,7 +1238,8 @@ void goto_checkt::bounds_check(
plus_exprt effective_offset(ode.offset(), pointer_offset(pointer));

assert(effective_offset.op0().type()==effective_offset.op1().type());
assert(effective_offset.type()==size.type());
if(effective_offset.type()!=size.type())
size.make_typecast(effective_offset.type());

binary_relation_exprt inequality(effective_offset, ID_lt, size);

Expand Down
1 change: 1 addition & 0 deletions src/analyses/goto_rw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ void rw_range_sett::get_objects_complex(

range_spect sub_size=
to_range_spect(pointer_offset_bits(op.type().subtype(), ns));
assert(sub_size>0);
range_spect offset=
(range_start==-1 || expr.id()==ID_complex_real) ? 0 : sub_size;

Expand Down
2 changes: 1 addition & 1 deletion src/analyses/invariant_set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Author: Daniel Kroening, [email protected]
#include <util/base_type.h>
#include <util/std_types.h>

#include <ansi-c/c_types.h>
#include <util/c_types.h>
#include <langapi/language_util.h>

#include "invariant_set.h"
Expand Down
2 changes: 1 addition & 1 deletion src/analyses/local_bitvector_analysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Author: Daniel Kroening, [email protected]
#include <util/std_code.h>
#include <util/expr_util.h>

#include <ansi-c/c_types.h>
#include <util/c_types.h>
#include <langapi/language_util.h>

#include "local_bitvector_analysis.h"
Expand Down
2 changes: 1 addition & 1 deletion src/analyses/local_cfg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Author: Daniel Kroening, [email protected]
#include <util/std_code.h>
#include <util/expr_util.h>

#include <ansi-c/c_types.h>
#include <util/c_types.h>
#include <langapi/language_util.h>

#endif
Expand Down
2 changes: 1 addition & 1 deletion src/analyses/local_may_alias.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Author: Daniel Kroening, [email protected]
#include <util/std_expr.h>
#include <util/std_code.h>

#include <ansi-c/c_types.h>
#include <util/c_types.h>
#include <langapi/language_util.h>

#include "local_may_alias.h"
Expand Down
1 change: 0 additions & 1 deletion src/ansi-c/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ SRC = anonymous_member.cpp \
c_typecheck_initializer.cpp \
c_typecheck_type.cpp \
c_typecheck_typecast.cpp \
c_types.cpp \
cprover_library.cpp \
designator.cpp \
expr2c.cpp \
Expand Down
1 change: 1 addition & 0 deletions src/ansi-c/ansi_c_convert_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Author: Daniel Kroening, [email protected]

#include <cassert>

#include <util/c_types.h>
#include <util/namespace.h>
#include <util/simplify_expr.h>
#include <util/config.h>
Expand Down
1 change: 0 additions & 1 deletion src/ansi-c/ansi_c_convert_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ Author: Daniel Kroening, [email protected]

#include <util/message.h>

#include "c_types.h"
#include "c_qualifiers.h"
#include "c_storage_spec.h"

Expand Down
2 changes: 1 addition & 1 deletion src/ansi-c/ansi_c_entry_point.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Author: Daniel Kroening, [email protected]
#include <util/cprover_prefix.h>
#include <util/prefix.h>

#include <ansi-c/c_types.h>
#include <util/c_types.h>
#include <ansi-c/string_constant.h>

#include <goto-programs/goto_functions.h>
Expand Down
2 changes: 1 addition & 1 deletion src/ansi-c/c_nondet_symbol_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Author: DiffBlue Limited. All rights reserved.
#include <sstream>

#include <util/arith_tools.h>
#include <util/c_types.h>
#include <util/fresh_symbol.h>
#include <util/std_types.h>
#include <util/std_code.h>
Expand All @@ -20,7 +21,6 @@ Author: DiffBlue Limited. All rights reserved.

#include <linking/zero_initializer.h>

#include <ansi-c/c_types.h>
#include <ansi-c/string_constant.h>

#include <goto-programs/goto_functions.h>
Expand Down
2 changes: 1 addition & 1 deletion src/ansi-c/c_preprocess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Author: Daniel Kroening, [email protected]

#include <fstream>

#include <util/c_types.h>
#include <util/config.h>
#include <util/message.h>
#include <util/tempfile.h>
Expand All @@ -29,7 +30,6 @@ Author: Daniel Kroening, [email protected]
#include <util/std_types.h>
#include <util/prefix.h>

#include "c_types.h"
#include "c_preprocess.h"

#define GCC_DEFINES_16 \
Expand Down
2 changes: 1 addition & 1 deletion src/ansi-c/c_sizeof.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ Author: Daniel Kroening, [email protected]

\*******************************************************************/

#include <util/c_types.h>
#include <util/config.h>
#include <util/arith_tools.h>
#include <util/simplify_expr.h>
#include <util/std_expr.h>

#include "c_sizeof.h"
#include "c_typecast.h"
#include "c_types.h"

/*******************************************************************\

Expand Down
2 changes: 1 addition & 1 deletion src/ansi-c/c_typecast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Author: Daniel Kroening, [email protected]
#include <cassert>

#include <util/arith_tools.h>
#include <util/c_types.h>
#include <util/config.h>
#include <util/expr_util.h>
#include <util/std_expr.h>
Expand All @@ -19,7 +20,6 @@ Author: Daniel Kroening, [email protected]
#include <util/simplify_expr.h>

#include "c_typecast.h"
#include "c_types.h"
#include "c_qualifiers.h"

/*******************************************************************\
Expand Down
6 changes: 3 additions & 3 deletions src/ansi-c/c_typecheck_expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Author: Daniel Kroening, [email protected]
#include <cassert>

#include <util/arith_tools.h>
#include <util/c_types.h>
#include <util/config.h>
#include <util/std_types.h>
#include <util/prefix.h>
Expand All @@ -19,7 +20,6 @@ Author: Daniel Kroening, [email protected]
#include <util/pointer_offset_size.h>
#include <util/pointer_predicates.h>

#include "c_types.h"
#include "c_typecast.h"
#include "c_typecheck_base.h"
#include "c_sizeof.h"
Expand Down Expand Up @@ -1318,8 +1318,8 @@ void c_typecheck_baset::typecheck_expr_typecast(exprt &expr)
// an integer/float of the same size
if((expr_type.id()==ID_signedbv ||
expr_type.id()==ID_unsignedbv) &&
pointer_offset_size(expr_type, *this)==
pointer_offset_size(op_vector_type, *this))
pointer_offset_bits(expr_type, *this)==
pointer_offset_bits(op_vector_type, *this))
{
}
else
Expand Down
2 changes: 1 addition & 1 deletion src/ansi-c/c_typecheck_initializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Author: Daniel Kroening, [email protected]
\*******************************************************************/

#include <util/arith_tools.h>
#include <util/c_types.h>
#include <util/config.h>
#include <util/type_eq.h>
#include <util/std_types.h>
Expand All @@ -16,7 +17,6 @@ Author: Daniel Kroening, [email protected]

#include <linking/zero_initializer.h>

#include "c_types.h"
#include "c_typecheck_base.h"
#include "string_constant.h"
#include "anonymous_member.h"
Expand Down
2 changes: 1 addition & 1 deletion src/ansi-c/c_typecheck_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ Author: Daniel Kroening, [email protected]

#include <unordered_set>

#include <util/c_types.h>
#include <util/config.h>
#include <util/simplify_expr.h>
#include <util/arith_tools.h>
#include <util/std_types.h>
#include <util/pointer_offset_size.h>

#include "c_typecheck_base.h"
#include "c_types.h"
#include "c_sizeof.h"
#include "c_qualifiers.h"
#include "ansi_c_declaration.h"
Expand Down
1 change: 0 additions & 1 deletion src/ansi-c/c_typecheck_typecast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ Author: Daniel Kroening, [email protected]

#include "c_typecast.h"
#include "c_typecheck_base.h"
#include "c_types.h"

/*******************************************************************\

Expand Down
2 changes: 1 addition & 1 deletion src/ansi-c/expr2c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Author: Daniel Kroening, [email protected]
#include <set>

#include <util/arith_tools.h>
#include <util/c_types.h>
#include <util/config.h>
#include <util/std_types.h>
#include <util/std_code.h>
Expand All @@ -37,7 +38,6 @@ Author: Daniel Kroening, [email protected]
#include "c_misc.h"
#include "c_qualifiers.h"
#include "expr2c.h"
#include "c_types.h"
#include "expr2c_class.h"

/*
Expand Down
3 changes: 1 addition & 2 deletions src/ansi-c/literals/convert_character_literal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ Author: Daniel Kroening, [email protected]
#include <cassert>

#include <util/arith_tools.h>
#include <util/c_types.h>
#include <util/std_expr.h>

#include "../c_types.h"

#include "unescape_string.h"
#include "convert_character_literal.h"

Expand Down
2 changes: 1 addition & 1 deletion src/ansi-c/literals/convert_float_literal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ Author: Daniel Kroening, [email protected]
#include <cassert>

#include <util/arith_tools.h>
#include <util/c_types.h>
#include <util/config.h>
#include <util/ieee_float.h>
#include <util/std_expr.h>
#include <util/std_types.h>
#include <util/string2int.h>

#include "../c_types.h"
#include "parse_float.h"
#include "convert_float_literal.h"

Expand Down
2 changes: 1 addition & 1 deletion src/ansi-c/literals/convert_string_literal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ Author: Daniel Kroening, [email protected]
#include <cassert>

#include <util/arith_tools.h>
#include <util/c_types.h>
#include <util/unicode.h>

#include "../string_constant.h"
#include "../c_types.h"

#include "unescape_string.h"
#include "convert_string_literal.h"
Expand Down
3 changes: 3 additions & 0 deletions src/ansi-c/padding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,9 @@ void add_padding(union_typet &type, const namespacet &ns)
mp_integer max_alignment=alignment(type, ns)*8;
mp_integer size_bits=pointer_offset_bits(type, ns);

if(size_bits<0)
throw "type of unknown size:\n"+type.pretty();

union_typet::componentst &components=type.components();

// Is the union packed?
Expand Down
3 changes: 1 addition & 2 deletions src/ansi-c/parser_static.inc
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#include <util/c_types.h>
#include <util/std_code.h>
#include <util/std_types.h>
#include <util/std_expr.h>
#include <util/string2int.h>

#include "c_types.h"

#define YYSTYPE unsigned
#define YYSTYPE_IS_TRIVIAL 1

Expand Down
2 changes: 1 addition & 1 deletion src/ansi-c/printf_formatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ Author: Daniel Kroening, [email protected]
#include <cassert>
#include <sstream>

#include <util/c_types.h>
#include <util/format_constant.h>
#include <util/simplify_expr.h>

#include "c_types.h"
#include "printf_formatter.h"

/*******************************************************************\
Expand Down
1 change: 0 additions & 1 deletion src/ansi-c/scanner.l
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ static int isatty(int) { return 0; }

#include <util/unicode.h>

#include "c_types.h"
#include "preprocessor_line.h"
#include "string_constant.h"

Expand Down
2 changes: 1 addition & 1 deletion src/ansi-c/string_constant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ Author: Daniel Kroening, [email protected]
\*******************************************************************/

#include <util/arith_tools.h>
#include <util/c_types.h>
#include <util/std_expr.h>

#include "string_constant.h"
#include "c_types.h"

/*******************************************************************\

Expand Down
2 changes: 1 addition & 1 deletion src/cpp/cpp_constructor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Author: Daniel Kroening, [email protected]
#include <util/arith_tools.h>
#include <util/std_types.h>

#include <ansi-c/c_types.h>
#include <util/c_types.h>

#include "cpp_typecheck.h"
#include "cpp_util.h"
Expand Down
2 changes: 1 addition & 1 deletion src/cpp/cpp_convert_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Author: Daniel Kroening, [email protected]
#include <util/arith_tools.h>
#include <util/std_types.h>

#include <ansi-c/c_types.h>
#include <util/c_types.h>

#include "cpp_convert_type.h"
#include "cpp_declaration.h"
Expand Down
2 changes: 1 addition & 1 deletion src/cpp/cpp_declarator_converter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Author: Daniel Kroening, [email protected]
#include <util/source_location.h>
#include <util/std_types.h>

#include <ansi-c/c_types.h>
#include <util/c_types.h>

#include "cpp_type2name.h"
#include "cpp_declarator_converter.h"
Expand Down
Loading