Skip to content

Commit 666c2f0

Browse files
Merge pull request #5440 from thomasspriggs/tas/goto-cc-object-bits-size
Add `--object-bits` option to goto-cc
2 parents b3a6cc4 + 06c5aa1 commit 666c2f0

File tree

12 files changed

+142
-0
lines changed

12 files changed

+142
-0
lines changed

doc/cprover-manual/goto-cc.md

+5
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ most important architectural parameters are:
112112
`sizeof(long int)` on various machines.
113113
- The width of pointers; for example, compare the value of `sizeof(int *)` on
114114
various machines.
115+
- The number of bits in a pointer which are used to differentiate between
116+
different objects. The remaining bits of a pointer are used for offsets
117+
within objects.
115118
- The [endianness](http://en.wikipedia.org/wiki/Endianness) of
116119
the architecture.
117120

@@ -129,6 +132,8 @@ following command-line arguments can be passed to the CPROVER tools:
129132
- The word-width can be set with `--16`, `--32`, `--64`.
130133
- The endianness can be defined with `--little-endian` and
131134
`--big-endian`.
135+
- The number of bits in a pointer used to differentiate between different
136+
objects can be set using `--object-bits x`. Where `x` is the number of bits.
132137

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

regression/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ else()
4747
add_subdirectory(goto-cl)
4848
endif()
4949
add_subdirectory(goto-cc-cbmc)
50+
add_subdirectory(goto-cc-cbmc-shared-options)
5051
add_subdirectory(cbmc-cpp)
5152
add_subdirectory(goto-cc-goto-analyzer)
5253
add_subdirectory(statement-list)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
if(WIN32)
2+
set(is_windows true)
3+
else()
4+
set(is_windows false)
5+
endif()
6+
7+
add_test_pl_tests(
8+
"${CMAKE_CURRENT_SOURCE_DIR}/chain.sh $<TARGET_FILE:goto-cc> $<TARGET_FILE:cbmc> ${is_windows}"
9+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
default: tests.log
2+
3+
include ../../src/config.inc
4+
include ../../src/common
5+
6+
ifeq ($(BUILD_ENV_),MSVC)
7+
exe=../../../src/goto-cc/goto-cl
8+
is_windows=true
9+
else
10+
exe=../../../src/goto-cc/goto-cc
11+
is_windows=false
12+
endif
13+
14+
test:
15+
@../test.pl -e -p -c '../chain.sh $(exe) ../../../src/cbmc/cbmc $(is_windows)'
16+
17+
tests.log:
18+
@../test.pl -e -p -c '../chain.sh $(exe) ../../../src/cbmc/cbmc $(is_windows)'
19+
20+
show:
21+
@for dir in *; do \
22+
if [ -d "$$dir" ]; then \
23+
vim -o "$$dir/*.c" "$$dir/*.out"; \
24+
fi; \
25+
done;
26+
27+
clean:
28+
@for dir in *; do \
29+
$(RM) tests.log; \
30+
if [ -d "$$dir" ]; then \
31+
cd "$$dir"; \
32+
$(RM) *.out *.gb; \
33+
cd ..; \
34+
fi \
35+
done
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env bash
2+
3+
goto_cc=$1
4+
cbmc=$2
5+
is_windows=$3
6+
7+
options=${*:4:$#-4}
8+
name=${*:$#}
9+
base_name=${name%.c}
10+
base_name=${base_name%.cpp}
11+
12+
if [[ "${is_windows}" == "true" ]]; then
13+
"${goto_cc}" "${name}" ${options}
14+
mv "${base_name}.exe" "${base_name}.gb"
15+
else
16+
"${goto_cc}" "${name}" -o "${base_name}.gb" ${options}
17+
fi
18+
19+
"${cbmc}" "${base_name}.gb" ${options}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
CORE
2+
test.c
3+
--function main
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
^VERIFICATION FAILED$
7+
assertion object_bits != 6: SUCCESS
8+
assertion object_bits != 8: FAILURE
9+
assertion object_bits != 10: SUCCESS
10+
--
11+
^warning: ignoring
12+
--
13+
Test that the default value for object-bits is 8.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
CORE
2+
test.c
3+
--function main --object-bits 6
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
^VERIFICATION FAILED$
7+
assertion object_bits != 6: FAILURE
8+
assertion object_bits != 8: SUCCESS
9+
assertion object_bits != 10: SUCCESS
10+
--
11+
^warning: ignoring
12+
--
13+
Test test running with fewer bits than usual results in correct setup of
14+
intrinsic constants.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
CORE
2+
test.c
3+
--function main --object-bits 10
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
^VERIFICATION FAILED$
7+
assertion object_bits != 6: SUCCESS
8+
assertion object_bits != 8: SUCCESS
9+
assertion object_bits != 10: FAILURE
10+
--
11+
^warning: ignoring
12+
--
13+
Test test running with more bits than usual results in correct setup of
14+
intrinsic constants.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include <assert.h>
2+
#include <stdlib.h>
3+
4+
size_t
5+
find_first_set(const size_t max_malloc_size, const size_t bits_accumulator)
6+
{
7+
if(max_malloc_size & 1)
8+
return bits_accumulator;
9+
return find_first_set(max_malloc_size >> 1, bits_accumulator + 1);
10+
}
11+
12+
size_t calculate_object_bits()
13+
{
14+
const size_t ptr_size = sizeof(void *) * 8;
15+
return ptr_size - find_first_set(__CPROVER_max_malloc_size, 1);
16+
}
17+
18+
int main()
19+
{
20+
void *temp = malloc(2);
21+
size_t object_bits = calculate_object_bits();
22+
assert(object_bits != 6);
23+
assert(object_bits != 8);
24+
assert(object_bits != 10);
25+
__CPROVER_assume("end of main.");
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
This directory is for tests where we -
2+
1) Run `goto-cc` on the specified input file, with the specified options.
3+
2) Run `cbmc` on the goto binary produced in step 1. Using the same options
4+
from the `.desc` file as were specified in step 1.

src/goto-cc/gcc_cmdline.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const char *goto_cc_options_with_separated_argument[]=
2828
"--native-linker",
2929
"--print-rejected-preprocessed-source",
3030
"--mangle-suffix",
31+
"--object-bits",
3132
nullptr
3233
};
3334

src/goto-cc/goto_cc_mode.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ void goto_cc_modet::help()
6666
" --native-assembler cmd command to invoke as assembler (goto-as only)\n"
6767
" --print-rejected-preprocessed-source file\n"
6868
" copy failing (preprocessed) source to file\n"
69+
" --object-bits number of bits used for object addresses\n"
6970
"\n";
7071
// clang-format on
7172
}

0 commit comments

Comments
 (0)