Skip to content

Commit a47020c

Browse files
author
Daniel Kroening
committed
use __CPROVER_size_t and __CPROVER_ssize_t for __CPROVER_POINTER_OBJECT/OFFSET
1 parent bfe3d3d commit a47020c

5 files changed

+19
-14
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

+3-6
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,8 +2168,8 @@ 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();
2171+
exprt pointer_object_expr=
2172+
unary_exprt(ID_pointer_object, expr.arguments()[0], expr.type());
21762173
pointer_object_expr.add_source_location()=source_location;
21772174

21782175
return pointer_object_expr;

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';

0 commit comments

Comments
 (0)