-
Notifications
You must be signed in to change notification settings - Fork 274
Add --object-bits
option to goto-cc
#5440
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
if(WIN32) | ||
set(is_windows true) | ||
else() | ||
set(is_windows false) | ||
endif() | ||
|
||
add_test_pl_tests( | ||
"${CMAKE_CURRENT_SOURCE_DIR}/chain.sh $<TARGET_FILE:goto-cc> $<TARGET_FILE:cbmc> ${is_windows}" | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
default: tests.log | ||
|
||
include ../../src/config.inc | ||
include ../../src/common | ||
|
||
ifeq ($(BUILD_ENV_),MSVC) | ||
exe=../../../src/goto-cc/goto-cl | ||
is_windows=true | ||
else | ||
exe=../../../src/goto-cc/goto-cc | ||
is_windows=false | ||
endif | ||
|
||
test: | ||
@../test.pl -e -p -c '../chain.sh $(exe) ../../../src/cbmc/cbmc $(is_windows)' | ||
|
||
tests.log: | ||
@../test.pl -e -p -c '../chain.sh $(exe) ../../../src/cbmc/cbmc $(is_windows)' | ||
|
||
show: | ||
@for dir in *; do \ | ||
if [ -d "$$dir" ]; then \ | ||
vim -o "$$dir/*.c" "$$dir/*.out"; \ | ||
fi; \ | ||
done; | ||
|
||
clean: | ||
@for dir in *; do \ | ||
$(RM) tests.log; \ | ||
if [ -d "$$dir" ]; then \ | ||
cd "$$dir"; \ | ||
$(RM) *.out *.gb; \ | ||
cd ..; \ | ||
fi \ | ||
done |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/usr/bin/env bash | ||
|
||
goto_cc=$1 | ||
cbmc=$2 | ||
is_windows=$3 | ||
|
||
options=${*:4:$#-4} | ||
name=${*:$#} | ||
base_name=${name%.c} | ||
base_name=${base_name%.cpp} | ||
|
||
if [[ "${is_windows}" == "true" ]]; then | ||
"${goto_cc}" "${name}" ${options} | ||
mv "${base_name}.exe" "${base_name}.gb" | ||
else | ||
"${goto_cc}" "${name}" -o "${base_name}.gb" ${options} | ||
fi | ||
|
||
"${cbmc}" "${base_name}.gb" ${options} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
CORE | ||
test.c | ||
--function main | ||
^EXIT=10$ | ||
^SIGNAL=0$ | ||
^VERIFICATION FAILED$ | ||
assertion object_bits != 6: SUCCESS | ||
assertion object_bits != 8: FAILURE | ||
assertion object_bits != 10: SUCCESS | ||
-- | ||
^warning: ignoring | ||
-- | ||
Test that the default value for object-bits is 8. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
CORE | ||
test.c | ||
--function main --object-bits 6 | ||
^EXIT=10$ | ||
^SIGNAL=0$ | ||
^VERIFICATION FAILED$ | ||
assertion object_bits != 6: FAILURE | ||
assertion object_bits != 8: SUCCESS | ||
assertion object_bits != 10: SUCCESS | ||
-- | ||
^warning: ignoring | ||
-- | ||
Test test running with fewer bits than usual results in correct setup of | ||
intrinsic constants. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
CORE | ||
test.c | ||
--function main --object-bits 10 | ||
^EXIT=10$ | ||
^SIGNAL=0$ | ||
^VERIFICATION FAILED$ | ||
assertion object_bits != 6: SUCCESS | ||
assertion object_bits != 8: SUCCESS | ||
assertion object_bits != 10: FAILURE | ||
-- | ||
^warning: ignoring | ||
-- | ||
Test test running with more bits than usual results in correct setup of | ||
intrinsic constants. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#include <assert.h> | ||
#include <stdlib.h> | ||
|
||
size_t | ||
find_first_set(const size_t max_malloc_size, const size_t bits_accumulator) | ||
{ | ||
if(max_malloc_size & 1) | ||
return bits_accumulator; | ||
return find_first_set(max_malloc_size >> 1, bits_accumulator + 1); | ||
} | ||
|
||
size_t calculate_object_bits() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO it would be unnecessary to reverse engineer the object bits here or even use the value of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The reason I chose to do it this way is that the previous incorrect behaviour resulted in a warning, but might not actually cause a failure without giving an input program which depends on the implications of the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, that makes sense. |
||
{ | ||
const size_t ptr_size = sizeof(void *) * 8; | ||
return ptr_size - find_first_set(__CPROVER_max_malloc_size, 1); | ||
} | ||
|
||
int main() | ||
{ | ||
void *temp = malloc(2); | ||
size_t object_bits = calculate_object_bits(); | ||
assert(object_bits != 6); | ||
assert(object_bits != 8); | ||
assert(object_bits != 10); | ||
__CPROVER_assume("end of main."); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
This directory is for tests where we - | ||
1) Run `goto-cc` on the specified input file, with the specified options. | ||
2) Run `cbmc` on the goto binary produced in step 1. Using the same options | ||
from the `.desc` file as were specified in step 1. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,7 @@ const char *goto_cc_options_with_separated_argument[]= | |
"--native-linker", | ||
"--print-rejected-preprocessed-source", | ||
"--mangle-suffix", | ||
"--object-bits", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't this be added to the other There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The original ticket referred to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no standard list of options in the base class. So it would need to be manually added and tested for each |
||
nullptr | ||
}; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add the expected results for the other assertions in here as well? Clearly it's supposed to be always 2 successes and one failure but that might be easier to see if its spelt out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.