Skip to content

Commit 8919fdc

Browse files
authored
Merge pull request diffblue#8292 from diffblue/no-body-assertion
generate assert(false) when calling undefined function
2 parents c3e5ba8 + 6c99724 commit 8919fdc

File tree

39 files changed

+108
-117
lines changed

39 files changed

+108
-117
lines changed

doc/man/cbmc.1

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -347,10 +347,6 @@ run full slicer (experimental)
347347
.TP
348348
\fB\-\-drop\-unused\-functions\fR
349349
drop functions trivially unreachable from main function
350-
.TP
351-
\fB\-\-havoc\-undefined\-functions\fR
352-
for any function that has no body, assign non\-deterministic values to
353-
any parameters passed as non\-const pointers and the return value
354350
.SS "Semantic transformations:"
355351
.TP
356352
\fB\-\-nondet\-static\fR

regression/cbmc-cpp/Overloading_Functions4/main.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
double pow(double _X, double _Y);
22
double pow(double _X, int _Y);
33
float pow(float _X, float _Y);
4-
float pow(float _X, int _Y);
4+
float pow(float _X, int _Y)
5+
{
6+
}
57
long double pow(long double _X, long double _Y);
68
long double pow(long double _X, int _Y);
79

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CORE
1+
KNOWNBUG
22
main.c
33
--pointer-check --bounds-check -D_FORTIFY_SOURCE=2 -D__OPTIMIZE__=2
44
^EXIT=0$
@@ -7,3 +7,5 @@ main.c
77
--
88
^\*\*\*\* WARNING: no body for function __fprintf_chk
99
^warning: ignoring
10+
--
11+
We are missing __builtin_va_arg_pack

regression/cbmc-library/printf-01/__printf_chk.desc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CORE
1+
KNOWNBUG
22
main.c
33
--pointer-check --bounds-check -D_FORTIFY_SOURCE=2 -D__OPTIMIZE__=2
44
^EXIT=10$
@@ -8,3 +8,5 @@ main.c
88
--
99
^\*\*\*\* WARNING: no body for function __printf_chk
1010
^warning: ignoring
11+
--
12+
We are missing __builtin_va_arg_pack
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
CORE
1+
KNOWNBUG
22
main.c
33
--pointer-check --bounds-check -D_FORTIFY_SOURCE=2 -D__OPTIMIZE__=2
44
^EXIT=0$
55
^SIGNAL=0$
66
^VERIFICATION SUCCESSFUL$
77
--
8-
^\*\*\*\* WARNING: no body for function __syslog_chk
98
^warning: ignoring
9+
--
10+
We are missing __builtin_va_arg_pack

regression/cbmc/Array_UF17/main.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ int istrchr(const char *s, int c);
3131
int istrrchr(const char *s, int c);
3232
int istrncmp(const char *s1, int start, const char *s2, size_t n);
3333
int istrstr(const char *haystack, const char *needle);
34-
char *r_strncpy(char *dest, const char *src, size_t n);
34+
char *r_strncpy(char *dest, const char *src, size_t n)
35+
{
36+
}
3537
char *r_strcpy(char *dest, const char *src);
3638
char *r_strcat(char *dest, const char *src);
3739
char *r_strncat(char *dest, const char *src, size_t n);

regression/cbmc/Function_Pointer5/main.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
// this is a pointer to a function that takes a function pointer as argument
22

3-
void signal1(int, void (*)(int));
4-
void signal2(int, void (*h)(int));
3+
void signal1(int, void (*)(int))
4+
{
5+
}
6+
7+
void signal2(int, void (*h)(int))
8+
{
9+
h(123);
10+
}
511

612
void handler(int x)
713
{

regression/cbmc/Malloc2/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
typedef unsigned int size_t;
1+
typedef __CPROVER_size_t size_t;
22
typedef int ssize_t;
33
typedef int atomic_t;
44
typedef unsigned gfp_t;

regression/cbmc/Pointer28/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CORE no-new-smt
1+
KNOWNBUG no-new-smt
22
main.c
33
--little-endian
44
^EXIT=0$

regression/cbmc/Promotion4/main.i

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
unsigned nondet_unsigned();
2+
13
int main(int argc, char *argv[])
24
{
35
__CPROVER_assert(sizeof(unsigned int) == 2, "[--16] size of int is 16 bit");
46
__CPROVER_assert(
57
sizeof(unsigned long) == 4, "[--LP32] size of long is 32 bit");
68

7-
unsigned int k = non_det_unsigned();
9+
unsigned int k = nondet_unsigned();
810
__CPROVER_assume(k < 1);
911
__CPROVER_assert(k != 0xffff, "false counter example 16Bit?");
1012

regression/cbmc/String_Abstraction11/anon-retval.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
void *malloc(unsigned);
1+
void *malloc(__CPROVER_size_t);
22

33
char *foo()
44
{

regression/cbmc/String_Abstraction19/structs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
void *malloc(unsigned);
1+
void *malloc(__CPROVER_size_t);
22

33
typedef struct str_struct
44
{
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
CORE
22
main.c
33

4+
^\[main\.no-body\.f\] line 9 no body for callee f: FAILURE$
5+
^\[main\.assertion\.1] line 10 assertion i==1: FAILURE$
6+
^VERIFICATION FAILED$
47
^EXIT=10$
58
^SIGNAL=0$
6-
^\*\*\*\* WARNING: no body for function f$
7-
^VERIFICATION FAILED$
89
--
910
^warning: ignoring
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
CORE
22
main.c
33

4+
^\[main\.no-body\.asd\] line 7 no body for callee asd: FAILURE$
5+
^\[main\.assertion\.1\] line 8 assertion v1==v2: FAILURE$
6+
^VERIFICATION FAILED$
47
^EXIT=10$
58
^SIGNAL=0$
6-
^\*\*\*\* WARNING: no body for function asd$
7-
^VERIFICATION FAILED$
89
--
910
^warning: ignoring

regression/cbmc/havoc_undefined_functions/main.c

Lines changed: 0 additions & 9 deletions
This file was deleted.

regression/cbmc/havoc_undefined_functions/test.desc

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
#include <assert.h>
22
#include <stdlib.h>
33

4+
_Bool nondet_bool();
5+
46
void main()
57
{
68
char *data;
7-
data = nondet() ? malloc(1) : malloc(2);
9+
data = nondet_bool() ? malloc(1) : malloc(2);
810
assert(__CPROVER_OBJECT_SIZE(data) <= 2);
911
}

regression/cbmc/issue_5952_soundness_bug_smt_encoding/test_short.desc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ short.c
44
^EXIT=0$
55
^SIGNAL=0$
66
^VERIFICATION SUCCESSFUL$
7-
\[main.assertion.\d\] line \d assertion __CPROVER_OBJECT_SIZE\(data\) <= 2: SUCCESS
7+
^\[main\.assertion\.\d\] line \d+ assertion __CPROVER_OBJECT_SIZE\(data\) <= 2: SUCCESS$
88
--
9-
\[main.assertion.\d\] line \d assertion __CPROVER_OBJECT_SIZE\(data\) <= 2: FAILURE
9+
^\[main\.assertion\.\d\] line \d+ assertion __CPROVER_OBJECT_SIZE\(data\) <= 2: FAILURE$
1010
--
1111
This is the reduced version of the issue described in
1212
https://github.com/diffblue/cbmc/issues/5952

regression/cbmc/memory_allocation2/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CORE
1+
KNOWNBUG
22
main.c
33

44
^EXIT=10$

regression/cbmc/pointer-overflow2/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CORE
1+
KNOWNBUG
22
main.c
33
--pointer-overflow-check
44
^EXIT=0$

regression/cbmc/union12/test.desc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CORE broken-smt-backend
1+
KNOWNBUG broken-smt-backend
22
main.c
33

44
^EXIT=10$
@@ -15,3 +15,5 @@ possible. With 77236cc34 (Avoid nesting of ID_with/byte_update by rewriting
1515
byte_extract to use the root object) the test already is trivial, however.
1616

1717
This test only fails when using SMT solvers as back-end on Windows.
18+
19+
No body for __CPROVER_allocated_memory

regression/contracts/assigns_replace_02/main.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
#include <assert.h>
22

3+
void bar(int *)
4+
{
5+
}
6+
37
void foo(int *x, int *y) __CPROVER_assigns(*x)
48
{
59
*x = 7;

regression/contracts/cprover-assignable-pass/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CORE
1+
KNOWNBUG
22
main.c
33

44
CALL __CPROVER_object_whole

regression/goto-instrument-wmm-core/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ else()
44
set(is_windows false)
55
endif()
66

7+
# These tests do not run with Visual Studio since they use
8+
# gcc's asm syntax.
9+
10+
if(NOT WIN32)
11+
712
add_test_pl_tests(
813
"${CMAKE_CURRENT_SOURCE_DIR}/chain.sh $<TARGET_FILE:goto-cc> $<TARGET_FILE:goto-instrument> $<TARGET_FILE:cbmc> ${is_windows}" -X glpk
914
)
15+
16+
endif()

regression/goto-instrument-wmm-core/Makefile

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
1+
# These tests do not run with Visual Studio since they use
2+
# gcc's asm syntax.
3+
14
default: tests.log
25

36
include ../../src/config.inc
47
include ../../src/common
58

69
ifeq ($(BUILD_ENV_),MSVC)
7-
exe=../../../src/goto-cc/goto-cl
8-
is_windows=true
10+
11+
test:
12+
13+
tests.log: ../test.pl
14+
915
else
10-
exe=../../../src/goto-cc/goto-cc
11-
is_windows=false
12-
endif
16+
17+
exe=../../../src/goto-cc/goto-cc
18+
is_windows=false
1319

1420
testalpha:
1521
@../test.pl -C -e -p -c '../chain.sh $(exe) ../../../src/goto-instrument/goto-instrument ../../../src/cbmc/cbmc $(is_windows)' -X glpk
@@ -29,6 +35,8 @@ test:
2935
tests.log:
3036
@../test.pl -e -p -c '../chain.sh $(exe) ../../../src/goto-instrument/goto-instrument ../../../src/cbmc/cbmc $(is_windows)' -X glpk
3137

38+
endif
39+
3240
clean:
3341
find . -name '*.out' -execdir $(RM) '{}' \;
3442
find . -name '*.gb' -execdir $(RM) '{}' \;
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
CORE
1+
KNOWNBUG
22
main.c
33
--dump-c
44
^EXIT=0$
55
^SIGNAL=0$
66
va_list
77
--
88
^warning: ignoring
9+
--
10+
We are missing __CPROVER_va_start
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
CORE
22
main.c
33
--inline
4-
^EXIT=0$
4+
^EXIT=10$
55
^SIGNAL=0$
6-
^VERIFICATION SUCCESSFUL$
6+
^VERIFICATION FAILED$
77
func1\(\)
88
ret.*=.*func2\(\)
9-
no body for function.*func1
10-
no body for function.*func2
9+
^\[\.no-body\.func1\] file main.c line 3 no body for callee func1: FAILURE$
10+
^\[\.no-body\.func2\] file main.c line 3 no body for callee func2: FAILURE$
1111
--
1212
^warning: ignoring

regression/goto-instrument/inline_17/test.desc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
CORE
22
main.c
33
--function-inline func1
4-
^EXIT=0$
4+
^EXIT=10$
55
^SIGNAL=0$
6-
^VERIFICATION SUCCESSFUL$
6+
^\[func1\.no-body\.func2\] line 3 no body for callee func2: FAILURE$
7+
^VERIFICATION FAILED$
78
func1\(\)
89
func2\(\)
910
--

regression/goto-instrument/remove-function-body1/test.desc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
CORE
22
main.c
33
--remove-function-body foo --remove-function-body bar
4-
^EXIT=0$
4+
^EXIT=10$
55
^SIGNAL=0$
6-
^VERIFICATION SUCCESSFUL$
6+
^\[main\.no-body\.foo\] line 19 no body for callee foo: FAILURE$
7+
^\[main\.no-body\.bar\] line 20 no body for callee bar: FAILURE$
8+
^VERIFICATION FAILED$
79
--
810
^warning: ignoring
911
^bar

src/ansi-c/library/syslog.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ void syslog(int priority, const char *format, ...)
2121
(void)*format;
2222
}
2323

24+
/* FUNCTION: _syslog$DARWIN_EXTSN */
25+
26+
void _syslog$DARWIN_EXTSN(int priority, const char *format, ...)
27+
{
28+
(void)priority;
29+
(void)*format;
30+
}
31+
2432
/* FUNCTION: __syslog_chk */
2533

2634
void __syslog_chk(int priority, int flag, const char *format, ...)

src/ansi-c/library_check.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ for f in "$@"; do
1515
$CC -std=gnu11 -E -include library/cprover.h -D__CPROVER_bool=_Bool -D__CPROVER_thread_local=__thread -DLIBRARY_CHECK -o __libcheck.i __libcheck.c
1616
$CC -S -Wall -Werror -pedantic -Wextra -std=gnu11 __libcheck.i \
1717
-o __libcheck.s -Wno-unused-label -Wno-unknown-pragmas \
18+
-Wno-dollar-in-identifier-extension \
1819
-Wno-gnu-line-marker -Wno-unknown-warning-option -Wno-psabi
1920
ec="${?}"
2021
rm __libcheck.s __libcheck.i __libcheck.c
@@ -73,6 +74,7 @@ perl -p -i -e 's/^__fprintf_chk\n//' __functions # fprintf-01/__fprintf_chk.desc
7374
perl -p -i -e 's/^__fread_chk\n//' __functions # fread-01/__fread_chk.desc
7475
perl -p -i -e 's/^__printf_chk\n//' __functions # printf-01/__printf_chk.desc
7576
perl -p -i -e 's/^__syslog_chk\n//' __functions # syslog-01/__syslog_chk.desc
77+
perl -p -i -e 's/^_syslog\$DARWIN_EXTSN\n//' __functions # syslog-01/test.desc
7678
perl -p -i -e 's/^__time64\n//' __functions # time
7779
perl -p -i -e 's/^__vfprintf_chk\n//' __functions # vfprintf-01/__vfprintf_chk.desc
7880

src/cbmc/cbmc_parse_options.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -285,9 +285,6 @@ void cbmc_parse_optionst::get_command_line_options(optionst &options)
285285
if(cmdline.isset("drop-unused-functions"))
286286
options.set_option("drop-unused-functions", true);
287287

288-
if(cmdline.isset("havoc-undefined-functions"))
289-
options.set_option("havoc-undefined-functions", true);
290-
291288
if(cmdline.isset("string-abstraction"))
292289
options.set_option("string-abstraction", true);
293290

@@ -1061,9 +1058,6 @@ void cbmc_parse_optionst::help()
10611058
" {y--full-slice} \t run full slicer (experimental)\n"
10621059
" {y--drop-unused-functions} \t drop functions trivially unreachable from"
10631060
" main function\n"
1064-
" {y--havoc-undefined-functions} \t for any function that has no body,"
1065-
" assign non-deterministic values to any parameters passed as non-const"
1066-
" pointers and the return value\n"
10671061
"\n"
10681062
"Semantic transformations:\n"
10691063
" {y--nondet-static} \t add nondeterministic initialization of variables"

src/cbmc/cbmc_parse_options.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ class optionst;
5555
OPT_SHOW_PROPERTIES \
5656
"(show-symbol-table)(show-parse-tree)" \
5757
"(drop-unused-functions)" \
58-
"(havoc-undefined-functions)" \
5958
"(property):(stop-on-fail)(trace)" \
6059
"(verbosity):(no-library)" \
6160
"(nondet-static)" \

0 commit comments

Comments
 (0)