Skip to content

Commit f7e5fb5

Browse files
authored
Merge pull request diffblue#2229 from diffblue/ssize_t
use __CPROVER_s/size_t for __CPROVER_POINTER_OBJECT/OFFSET
2 parents 1a504c9 + 1a7235d commit f7e5fb5

6 files changed

+31
-26
lines changed

doc/cbmc-user-manual.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -2193,8 +2193,8 @@ section on [Assumptions and Assertions](modeling-assertions.shtml).
21932193
#### \_\_CPROVER\_same\_object, \_\_CPROVER\_POINTER\_OBJECT, \_\_CPROVER\_POINTER\_OFFSET, \_\_CPROVER\_DYNAMIC\_OBJECT
21942194

21952195
_Bool __CPROVER_same_object(const void *, const void *);
2196-
unsigned __CPROVER_POINTER_OBJECT(const void *p);
2197-
signed __CPROVER_POINTER_OFFSET(const void *p);
2196+
__CPROVER_size_t __CPROVER_POINTER_OBJECT(const void *p);
2197+
__CPROVER_ssize_t __CPROVER_POINTER_OFFSET(const void *p);
21982198
_Bool __CPROVER_DYNAMIC_OBJECT(const void *p);
21992199

22002200
The function **\_\_CPROVER\_same\_object** returns true if the two

src/ansi-c/ansi_c_internal_additions.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Author: Daniel Kroening, [email protected]
88

99
#include "ansi_c_internal_additions.h"
1010

11+
#include <util/c_types.h>
1112
#include <util/config.h>
1213

1314
#include <linking/static_lifetime_init.h>
@@ -126,6 +127,8 @@ void ansi_c_internal_additions(std::string &code)
126127
code+=
127128
"# 1 \"<built-in-additions>\"\n"
128129
"typedef __typeof__(sizeof(int)) __CPROVER_size_t;\n"
130+
"typedef "+c_type_as_string(signed_size_type().get(ID_C_c_type))+
131+
" __CPROVER_ssize_t;\n"
129132
"const unsigned __CPROVER_constant_infinity_uint;\n"
130133
"typedef void __CPROVER_integer;\n"
131134
"typedef void __CPROVER_rational;\n"

src/ansi-c/c_typecheck_expr.cpp

+4-8
Original file line numberDiff line numberDiff line change
@@ -2157,10 +2157,7 @@ exprt c_typecheck_baset::do_special_functions(
21572157
exprt pointer_offset_expr=pointer_offset(expr.arguments().front());
21582158
pointer_offset_expr.add_source_location()=source_location;
21592159

2160-
if(expr.type()!=pointer_offset_expr.type())
2161-
pointer_offset_expr.make_typecast(expr.type());
2162-
2163-
return pointer_offset_expr;
2160+
return typecast_exprt::conditional_cast(pointer_offset_expr, expr.type());
21642161
}
21652162
else if(identifier==CPROVER_PREFIX "POINTER_OBJECT")
21662163
{
@@ -2171,11 +2168,10 @@ exprt c_typecheck_baset::do_special_functions(
21712168
throw 0;
21722169
}
21732170

2174-
exprt pointer_object_expr=exprt(ID_pointer_object, expr.type());
2175-
pointer_object_expr.operands()=expr.arguments();
2176-
pointer_object_expr.add_source_location()=source_location;
2171+
exprt pointer_object_expr = pointer_object(expr.arguments().front());
2172+
pointer_object_expr.add_source_location() = source_location;
21772173

2178-
return pointer_object_expr;
2174+
return typecast_exprt::conditional_cast(pointer_object_expr, expr.type());
21792175
}
21802176
else if(identifier=="__builtin_bswap16" ||
21812177
identifier=="__builtin_bswap32" ||

src/ansi-c/cprover_builtin_headers.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ void __CPROVER_fence(const char *kind, ...);
3333
void CBMC_trace(int lvl, const char *event, ...);
3434

3535
// pointers
36-
unsigned __CPROVER_POINTER_OBJECT(const void *p);
37-
signed __CPROVER_POINTER_OFFSET(const void *p);
38-
__CPROVER_bool __CPROVER_DYNAMIC_OBJECT(const void *p);
36+
__CPROVER_size_t __CPROVER_POINTER_OBJECT(const void *);
37+
__CPROVER_ssize_t __CPROVER_POINTER_OFFSET(const void *);
38+
__CPROVER_bool __CPROVER_DYNAMIC_OBJECT(const void *);
3939
void __CPROVER_allocated_memory(__CPROVER_size_t address, __CPROVER_size_t extent);
4040

4141
// float stuff

src/cpp/cpp_internal_additions.cpp

+8-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Author: Daniel Kroening, [email protected]
1010

1111
#include <ostream>
1212

13+
#include <util/c_types.h>
1314
#include <util/config.h>
1415

1516
#include <ansi-c/ansi_c_internal_additions.h>
@@ -64,7 +65,11 @@ void cpp_internal_additions(std::ostream &out)
6465

6566
// types
6667
out << "typedef __typeof__(sizeof(int)) __CPROVER::size_t;" << '\n';
67-
out << "typedef __typeof__(sizeof(int)) __CPROVER_size_t;" << '\n';
68+
out << "typedef __CPROVER::size_t __CPROVER_size_t;" << '\n';
69+
out << "typedef "
70+
<< c_type_as_string(signed_size_type().get(ID_C_c_type))
71+
<< " __CPROVER::ssize_t;" << '\n';
72+
out << "typedef __CPROVER::ssize_t __CPROVER_ssize_t;" << '\n';
6873

6974
// assume/assert
7075
out << "extern \"C\" void assert(bool assertion);" << '\n';
@@ -85,8 +90,8 @@ void cpp_internal_additions(std::ostream &out)
8590
out << "extern \"C\" void __CPROVER::atomic_end();" << '\n';
8691

8792
// pointers
88-
out << "extern \"C\" unsigned __CPROVER_POINTER_OBJECT(const void *p);\n";
89-
out << "extern \"C\" signed __CPROVER_POINTER_OFFSET(const void *p);" << '\n';
93+
out << "extern \"C\" __CPROVER::size_t __CPROVER_POINTER_OBJECT(const void *);\n";
94+
out << "extern \"C\" __CPROVER::ssize_t __CPROVER_POINTER_OFFSET(const void *);" << '\n';
9095
out << "extern \"C\" bool __CPROVER_DYNAMIC_OBJECT(const void *p);" << '\n';
9196
// NOLINTNEXTLINE(whitespace/line_length)
9297
out << "extern \"C\" extern unsigned char __CPROVER_memory[__CPROVER::constant_infinity_uint];" << '\n';

src/util/pointer_predicates.h

+11-10
Original file line numberDiff line numberDiff line change
@@ -17,38 +17,39 @@ class namespacet;
1717
class typet;
1818

1919
exprt same_object(const exprt &p1, const exprt &p2);
20-
exprt deallocated(const exprt &pointer, const namespacet &ns);
21-
exprt dead_object(const exprt &pointer, const namespacet &ns);
22-
exprt dynamic_size(const namespacet &ns);
20+
exprt deallocated(const exprt &pointer, const namespacet &);
21+
exprt dead_object(const exprt &pointer, const namespacet &);
22+
exprt dynamic_size(const namespacet &);
2323
exprt pointer_offset(const exprt &pointer);
24-
exprt malloc_object(const exprt &pointer, const namespacet &ns);
24+
exprt pointer_object(const exprt &pointer);
25+
exprt malloc_object(const exprt &pointer, const namespacet &);
2526
exprt object_size(const exprt &pointer);
2627
exprt pointer_object_has_type(
27-
const exprt &pointer, const typet &type, const namespacet &ns);
28+
const exprt &pointer, const typet &type, const namespacet &);
2829
exprt dynamic_object(const exprt &pointer);
2930
exprt good_pointer(const exprt &pointer);
30-
exprt good_pointer_def(const exprt &pointer, const namespacet &ns);
31+
exprt good_pointer_def(const exprt &pointer, const namespacet &);
3132
exprt null_object(const exprt &pointer);
3233
exprt null_pointer(const exprt &pointer);
3334
exprt integer_address(const exprt &pointer);
3435
exprt invalid_pointer(const exprt &pointer);
3536
exprt dynamic_object_lower_bound(
3637
const exprt &pointer,
37-
const namespacet &ns,
38+
const namespacet &,
3839
const exprt &offset);
3940
exprt dynamic_object_upper_bound(
4041
const exprt &pointer,
4142
const typet &dereference_type,
42-
const namespacet &ns,
43+
const namespacet &,
4344
const exprt &access_size);
4445
exprt object_lower_bound(
4546
const exprt &pointer,
46-
const namespacet &ns,
47+
const namespacet &,
4748
const exprt &offset);
4849
exprt object_upper_bound(
4950
const exprt &pointer,
5051
const typet &dereference_type,
51-
const namespacet &ns,
52+
const namespacet &,
5253
const exprt &access_size);
5354

5455
#endif // CPROVER_UTIL_POINTER_PREDICATES_H

0 commit comments

Comments
 (0)