Skip to content

Commit 905033e

Browse files
authored
Merge pull request #7858 from tautschnig/features/objects-bits-set-up
Permit re-setting --object-bits
2 parents 5ae5499 + 97e2439 commit 905033e

33 files changed

+159
-229
lines changed

doc/cprover-manual/goto-cc.md

-5
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,6 @@ most important architectural parameters are:
132132
`sizeof(long int)` on various machines.
133133
- The width of pointers; for example, compare the value of `sizeof(int *)` on
134134
various machines.
135-
- The number of bits in a pointer which are used to differentiate between
136-
different objects. The remaining bits of a pointer are used for offsets
137-
within objects.
138135
- The [endianness](http://en.wikipedia.org/wiki/Endianness) of
139136
the architecture.
140137

@@ -152,8 +149,6 @@ following command-line arguments can be passed to the CPROVER tools:
152149
- The word-width can be set with `--16`, `--32`, `--64`.
153150
- The endianness can be defined with `--little-endian` and
154151
`--big-endian`.
155-
- The number of bits in a pointer used to differentiate between different
156-
objects can be set using `--object-bits x`. Where `x` is the number of bits.
157152

158153
When using a goto binary, CBMC and the other tools read the
159154
configuration from the binary. The setting when running goto-cc is

doc/man/goto-cc.1

+4-3
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,10 @@ files.
9696
.TP
9797
\fB\-\-print\-rejected\-preprocessed\-source\fR \fIfile\fR
9898
Copy failing (preprocessed) source to \fIfile\fR.
99-
.TP
100-
\fB\-\-object\-bits\fR \fIN\fR
101-
Configure the number of bits used for object numbering in CBMC's pointer encoding.
99+
.SH BACKWARD COMPATIBILITY
100+
.B goto\-cc
101+
will warn and ignore the use of \fB\-\-object\-bits\fR, which previous versions
102+
processed. This option now instead needs to be passed to \fBcbmc\fR(1).
102103
.SH ENVIRONMENT
103104
All tools honor the TMPDIR environment variable when generating temporary
104105
files and directories.

regression/CMakeLists.txt

-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ else()
6363
add_subdirectory(goto-cl)
6464
endif()
6565
add_subdirectory(goto-cc-cbmc)
66-
add_subdirectory(goto-cc-cbmc-shared-options)
6766
add_subdirectory(cbmc-cpp)
6867
add_subdirectory(goto-cc-goto-analyzer)
6968
add_subdirectory(goto-analyzer-simplify)

regression/Makefile

-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ DIRS = cbmc-shadow-memory \
3636
goto-gcc \
3737
goto-cl \
3838
goto-cc-cbmc \
39-
goto-cc-cbmc-shared-options \
4039
cbmc-cpp \
4140
goto-cc-goto-analyzer \
4241
goto-analyzer-simplify \

regression/cbmc/simplify_singleton_interval_7690/singleton_interval_in_assume_7690.c

-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
#include <stdlib.h>
66
#include <stdint.h>
77

8-
extern size_t __CPROVER_max_malloc_size;
9-
108
#if defined(_WIN32) && defined(_M_X64)
119
int __builtin_clzll(unsigned long long);
1210
#define __nof_symex_objects \

regression/contracts-dfcc/memory-predicates-pointer-in-range-requires/test.desc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CORE dfcc-only
1+
THOROUGH dfcc-only
22
main.c
33
--malloc-may-fail --malloc-fail-null --dfcc main --enforce-contract foo _ --pointer-check --pointer-primitive-check
44
^EXIT=0$

regression/goto-cc-cbmc-shared-options/CMakeLists.txt

-11
This file was deleted.

regression/goto-cc-cbmc-shared-options/Makefile

-30
This file was deleted.

regression/goto-cc-cbmc-shared-options/README.md

-4
This file was deleted.

regression/goto-cc-cbmc-shared-options/chain.sh

-20
This file was deleted.

regression/goto-cc-cbmc-shared-options/object-bits/fewer_bits.desc regression/goto-cc-cbmc/object-bits/fewer_bits.desc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CORE winbug
1+
CORE
22
test.c
33
--function main --object-bits 6
44
^EXIT=10$

regression/goto-cc-cbmc-shared-options/object-bits/more_bits.desc regression/goto-cc-cbmc/object-bits/more_bits.desc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CORE winbug
1+
CORE
22
test.c
33
--function main --object-bits 10
44
^EXIT=10$

src/ansi-c/ansi_c_internal_additions.cpp

+3-31
Original file line numberDiff line numberDiff line change
@@ -124,34 +124,6 @@ static std::string architecture_string(T value, const char *s)
124124
std::string(s) + "=" + std::to_string(value) + ";\n";
125125
}
126126

127-
/// The maximum allocation size is determined by the number of bits that
128-
/// are left in the pointer of width \p pointer_width.
129-
///
130-
/// The allocation size cannot exceed the number represented by the (signed)
131-
/// offset, otherwise it would not be possible to store a pointer into a
132-
/// valid bit of memory. Therefore, the max allocation size is
133-
/// 2^(offset_bits - 1), where the offset bits is the number of bits left in the
134-
/// pointer after the object bits.
135-
///
136-
/// The offset must be signed, as a pointer can point to the end of the memory
137-
/// block, and needs to be able to point back to the start.
138-
/// \param pointer_width: The width of the pointer
139-
/// \param object_bits : The number of bits used to represent the ID
140-
/// \return The size in bytes of the maximum allocation supported.
141-
static mp_integer
142-
max_malloc_size(std::size_t pointer_width, std::size_t object_bits)
143-
{
144-
PRECONDITION(pointer_width >= 1);
145-
PRECONDITION(object_bits < pointer_width);
146-
PRECONDITION(object_bits >= 1);
147-
const auto offset_bits = pointer_width - object_bits;
148-
// We require the offset to be able to express upto allocation_size - 1,
149-
// but also down to -allocation_size, therefore the size is allowable
150-
// is number of bits, less the signed bit.
151-
const auto bits_for_positive_offset = offset_bits - 1;
152-
return ((mp_integer)1) << (mp_integer)bits_for_positive_offset;
153-
}
154-
155127
void ansi_c_internal_additions(std::string &code, bool support_float16_type)
156128
{
157129
// clang-format off
@@ -175,9 +147,9 @@ void ansi_c_internal_additions(std::string &code, bool support_float16_type)
175147
CPROVER_PREFIX "size_t size, " CPROVER_PREFIX "bool zero);\n"
176148
"void " CPROVER_PREFIX "deallocate(void *);\n"
177149

178-
CPROVER_PREFIX "size_t " CPROVER_PREFIX "max_malloc_size="+
179-
integer2string(max_malloc_size(config.ansi_c.pointer_width, config
180-
.bv_encoding.object_bits));
150+
CPROVER_PREFIX "thread_local " CPROVER_PREFIX "size_t "
151+
CPROVER_PREFIX "max_malloc_size="+
152+
integer2string(config.max_malloc_size());
181153
if(config.ansi_c.pointer_width==config.ansi_c.long_int_width)
182154
code += "UL;\n";
183155
else if(config.ansi_c.pointer_width==config.ansi_c.long_long_int_width)

src/ansi-c/cprover_library.h

+1
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,5 @@ void cprover_c_library_factory_force_load(
5252
const std::set<irep_idt> &functions,
5353
symbol_table_baset &symbol_table,
5454
message_handlert &message_handler);
55+
5556
#endif // CPROVER_ANSI_C_CPROVER_LIBRARY_H

src/ansi-c/library/cprover.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,11 @@ extern const void *__CPROVER_deallocated;
2626
extern const void *__CPROVER_memory_leak;
2727

2828
extern int __CPROVER_malloc_failure_mode;
29-
extern __CPROVER_size_t __CPROVER_max_malloc_size;
3029
extern __CPROVER_bool __CPROVER_malloc_may_fail;
30+
// The maximum size of an object that we can handle under the object:offset
31+
// pointer encoding. Marked thread-local as it is a per-analysis constant that
32+
// can safely be constant-propagated even in concurrent execution.
33+
extern __CPROVER_thread_local __CPROVER_size_t __CPROVER_max_malloc_size;
3134

3235
// malloc failure modes
3336
extern int __CPROVER_malloc_failure_mode_return_null;

src/ansi-c/library/cprover_contracts.c

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#define __CPROVER_contracts_library_defined
88

99
// external dependencies
10-
extern __CPROVER_size_t __CPROVER_max_malloc_size;
1110
const void *__CPROVER_alloca_object = 0;
1211
extern const void *__CPROVER_deallocated;
1312
const void *__CPROVER_new_object = 0;

src/cbmc/cbmc_parse_options.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,8 @@ int cbmc_parse_optionst::get_goto_program(
808808

809809
goto_model = initialize_goto_model(cmdline.args, ui_message_handler, options);
810810

811+
update_max_malloc_size(goto_model, ui_message_handler);
812+
811813
if(cmdline.isset("show-symbol-table"))
812814
{
813815
show_symbol_table(goto_model, ui_message_handler);

src/goto-cc/gcc_cmdline.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ const char *goto_cc_options_with_separated_argument[]=
2929
"--native-linker",
3030
"--print-rejected-preprocessed-source",
3131
"--mangle-suffix",
32-
"--object-bits",
3332
nullptr
3433
};
3534

src/goto-cc/goto_cc_mode.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ void goto_cc_modet::help()
7474
"symbols\n"
7575
" {y--print-rejected-preprocessed-source} {ufile} \t "
7676
"copy failing (preprocessed) source to file\n"
77-
" {y--object-bits} {N} \t number of bits used for object addresses\n"
7877
"\n");
7978
}
8079

src/goto-instrument/nondet_static.cpp

+16-24
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,17 @@ bool is_nondet_initializable_static(
7777
/// assigned to nondet-initializable static variables with nondeterministic
7878
/// values.
7979
/// \param ns: Namespace for resolving type information.
80-
/// \param [out] goto_functions: Existing goto-functions to be updated.
80+
/// \param [inout] goto_model: Existing goto-functions and symbol table to
81+
/// be updated.
8182
/// \param fct_name: Name of the goto-function to be updated.
8283
static void nondet_static(
8384
const namespacet &ns,
84-
goto_functionst &goto_functions,
85+
goto_modelt &goto_model,
8586
const irep_idt &fct_name)
8687
{
8788
goto_functionst::function_mapt::iterator fct_entry =
88-
goto_functions.function_map.find(fct_name);
89-
CHECK_RETURN(fct_entry != goto_functions.function_map.end());
89+
goto_model.goto_functions.function_map.find(fct_name);
90+
CHECK_RETURN(fct_entry != goto_model.goto_functions.function_map.end());
9091

9192
goto_programt &init = fct_entry->second.body;
9293

@@ -99,11 +100,11 @@ static void nondet_static(
99100

100101
if(is_nondet_initializable_static(sym, ns))
101102
{
102-
const auto source_location = instruction.source_location();
103-
instruction = goto_programt::make_assignment(
104-
code_assignt(
105-
sym, side_effect_expr_nondett(sym.type(), source_location)),
106-
source_location);
103+
side_effect_expr_nondett nondet{
104+
sym.type(), instruction.source_location()};
105+
instruction.assign_rhs_nonconst() = nondet;
106+
goto_model.symbol_table.get_writeable_ref(sym.get_identifier()).value =
107+
nondet;
107108
}
108109
}
109110
else if(instruction.is_function_call())
@@ -113,33 +114,24 @@ static void nondet_static(
113114
// see cpp/cpp_typecheck.cpp, which creates initialization functions
114115
if(fsym.get_identifier().starts_with("#cpp_dynamic_initialization#"))
115116
{
116-
nondet_static(ns, goto_functions, fsym.get_identifier());
117+
nondet_static(ns, goto_model, fsym.get_identifier());
117118
}
118119
}
119120
}
120121

121122
// update counters etc.
122-
goto_functions.update();
123-
}
124-
125-
/// Nondeterministically initializes global scope variables in
126-
/// CPROVER_initialize function.
127-
/// \param ns: Namespace for resolving type information.
128-
/// \param [out] goto_functions: Existing goto-functions to be updated.
129-
void nondet_static(const namespacet &ns, goto_functionst &goto_functions)
130-
{
131-
nondet_static(ns, goto_functions, INITIALIZE_FUNCTION);
123+
goto_model.goto_functions.update();
132124
}
133125

134126
/// First main entry point of the module. Nondeterministically initializes
135127
/// global scope variables, except for constants (such as string literals, final
136128
/// fields) and internal variables (such as CPROVER and symex variables,
137129
/// language specific internal variables).
138-
/// \param [out] goto_model: Existing goto-model to be updated.
130+
/// \param [inout] goto_model: Existing goto-model to be updated.
139131
void nondet_static(goto_modelt &goto_model)
140132
{
141133
const namespacet ns(goto_model.symbol_table);
142-
nondet_static(ns, goto_model.goto_functions);
134+
nondet_static(ns, goto_model, INITIALIZE_FUNCTION);
143135
}
144136

145137
/// Second main entry point of the module. Nondeterministically initializes
@@ -199,7 +191,7 @@ void nondet_static(
199191
}
200192
}
201193

202-
nondet_static(ns, goto_model.goto_functions, INITIALIZE_FUNCTION);
194+
nondet_static(ns, goto_model, INITIALIZE_FUNCTION);
203195
}
204196

205197
/// Nondeterministically initializes global scope variables that
@@ -227,5 +219,5 @@ void nondet_static_matching(goto_modelt &goto_model, const std::string &regex)
227219
}
228220

229221
const namespacet ns(goto_model.symbol_table);
230-
nondet_static(ns, goto_model.goto_functions, INITIALIZE_FUNCTION);
222+
nondet_static(ns, goto_model, INITIALIZE_FUNCTION);
231223
}

src/goto-instrument/nondet_static.h

-4
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@ bool is_nondet_initializable_static(
3232
const symbol_exprt &symbol_expr,
3333
const namespacet &ns);
3434

35-
void nondet_static(
36-
const namespacet &ns,
37-
goto_functionst &goto_functions);
38-
3935
void nondet_static(goto_modelt &);
4036

4137
void nondet_static(goto_modelt &, const std::set<std::string> &);

src/goto-programs/initialize_goto_model.cpp

+29
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ Author: Daniel Kroening, [email protected]
1111

1212
#include "initialize_goto_model.h"
1313

14+
#include <util/arith_tools.h>
15+
#include <util/c_types.h>
1416
#include <util/config.h>
1517
#include <util/exception_utils.h>
1618
#include <util/message.h>
@@ -22,6 +24,7 @@ Author: Daniel Kroening, [email protected]
2224
#include <langapi/language.h>
2325
#include <langapi/language_file.h>
2426
#include <langapi/mode.h>
27+
#include <linking/static_lifetime_init.h>
2528

2629
#include "goto_convert_functions.h"
2730
#include "read_goto_binary.h"
@@ -236,3 +239,29 @@ goto_modelt initialize_goto_model(
236239

237240
return goto_model;
238241
}
242+
243+
void update_max_malloc_size(
244+
goto_modelt &goto_model,
245+
message_handlert &message_handler)
246+
{
247+
if(!goto_model.symbol_table.has_symbol(CPROVER_PREFIX "max_malloc_size"))
248+
return;
249+
250+
const auto previous_max_malloc_size_value = numeric_cast<mp_integer>(
251+
goto_model.symbol_table.lookup_ref(CPROVER_PREFIX "max_malloc_size").value);
252+
const mp_integer current_max_malloc_size = config.max_malloc_size();
253+
254+
if(
255+
!previous_max_malloc_size_value.has_value() ||
256+
*previous_max_malloc_size_value != current_max_malloc_size)
257+
{
258+
symbolt &max_malloc_size_sym = goto_model.symbol_table.get_writeable_ref(
259+
CPROVER_PREFIX "max_malloc_size");
260+
max_malloc_size_sym.value =
261+
from_integer(current_max_malloc_size, size_type());
262+
max_malloc_size_sym.value.set(ID_C_no_nondet_initialization, true);
263+
264+
if(goto_model.can_produce_function(INITIALIZE_FUNCTION))
265+
recreate_initialize_function(goto_model, message_handler);
266+
}
267+
}

0 commit comments

Comments
 (0)