Skip to content

Commit 0bb2320

Browse files
author
Daniel Kroening
authored
Merge pull request #1326 from tautschnig/ansi-c-library-fixes
[develop->master] C library: cleanup and syntax error fixes
2 parents b8fce65 + 774fb0a commit 0bb2320

17 files changed

+368
-134
lines changed

.travis.yml

+2
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ install:
158158
- ccache --max-size=1G
159159
- COMMAND="make -C src minisat2-download" &&
160160
eval ${PRE_COMMAND} ${COMMAND}
161+
- COMMAND="make -C src/ansi-c library_check" &&
162+
eval ${PRE_COMMAND} ${COMMAND}
161163
- COMMAND="make -C src CXX=\"$COMPILER\" CXXFLAGS=\"-Wall -Werror -pedantic -O2 -g $EXTRA_CXXFLAGS\" -j2" &&
162164
eval ${PRE_COMMAND} ${COMMAND}
163165
- COMMAND="make -C src CXX=\"$COMPILER\" CXXFLAGS=\"$FLAGS $EXTRA_CXXFLAGS\" -j2 clobber.dir memory-models.dir musketeer.dir" &&

src/ansi-c/Makefile

+5-4
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,15 @@ else
9494
endif
9595
library_check: library/*.c
9696
for f in $(filter-out $(platform_unavail), $^) ; do \
97+
echo "Checking $$f" ; \
9798
cp $$f __libcheck.c ; \
98-
sed -i 's/__builtin_[^v]/s&/' __libcheck.c ; \
99-
sed -i 's/__sync_/s&/' __libcheck.c ; \
100-
sed -i 's/__noop/s&/' __libcheck.c ; \
99+
perl -p -i -e 's/(__builtin_[^v])/s$$1/' __libcheck.c ; \
100+
perl -p -i -e 's/(__sync_)/s$$1/' __libcheck.c ; \
101+
perl -p -i -e 's/(__noop)/s$$1/' __libcheck.c ; \
101102
$(CC) -std=gnu99 -E -include library/cprover.h -D__CPROVER_bool=_Bool \
102103
-D__CPROVER_thread_local=__thread -DLIBRARY_CHECK -o __libcheck.i __libcheck.c ; \
103104
$(CC) -S -Wall -Werror -pedantic -Wextra -std=gnu99 __libcheck.i -o __libcheck.s \
104-
-Wno-unused-label -Wno-uninitialized ; \
105+
-Wno-unused-label ; \
105106
ec=$$? ; \
106107
$(RM) __libcheck.s __libcheck.i __libcheck.c ; \
107108
[ $$ec -eq 0 ] || exit $$ec ; \

src/ansi-c/library/fcntl.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
#define __CPROVER_FCNTL_H_INCLUDED
66
#endif
77

8+
int __VERIFIER_nondet_int();
9+
810
int fcntl(int fd, int cmd, ...)
911
{
1012
__CPROVER_HIDE:;
11-
int return_value;
13+
int return_value=__VERIFIER_nondet_int();
1214
(void)fd;
1315
(void)cmd;
1416
return return_value;

src/ansi-c/library/getopt.c

+19-8
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@ extern int optind;
88
#define __CPROVER_STRING_H_INCLUDED
99
#endif
1010

11-
inline int getopt(int argc, char * const argv[],
12-
const char *optstring)
11+
__CPROVER_bool __VERIFIER_nondet___CPROVER_bool();
12+
size_t __VERIFIER_nondet_size_t();
13+
14+
inline int getopt(
15+
int argc, char * const argv[], const char *optstring)
1316
{
1417
__CPROVER_HIDE:;
1518
int result=-1;
@@ -20,25 +23,26 @@ inline int getopt(int argc, char * const argv[],
2023
if(optind>=argc || argv[optind][0]!='-')
2124
return -1;
2225

23-
size_t result_index;
26+
size_t result_index=__VERIFIER_nondet_size_t();
2427
__CPROVER_assume(
2528
result_index<strlen(optstring) && optstring[result_index]!=':');
2629
#ifdef __CPROVER_STRING_ABSTRACTION
2730
__CPROVER_assert(__CPROVER_is_zero_string(optstring),
2831
"getopt zero-termination of 3rd argument");
2932
#endif
3033

31-
_Bool found;
34+
__CPROVER_bool found=__VERIFIER_nondet___CPROVER_bool();
3235
if(found)
3336
{
3437
result=optstring[result_index];
38+
__CPROVER_bool skipped=__VERIFIER_nondet___CPROVER_bool();
3539
if(skipped)
3640
++optind;
3741
}
3842

3943
if(result!=-1 && optind<argc && optstring[result_index+1]==':')
4044
{
41-
_Bool has_no_arg;
45+
__CPROVER_bool has_no_arg=__VERIFIER_nondet___CPROVER_bool();
4246
if(has_no_arg)
4347
{
4448
optarg=argv[optind];
@@ -53,10 +57,17 @@ inline int getopt(int argc, char * const argv[],
5357

5458
/* FUNCTION: getopt_long */
5559

56-
int getopt(int argc, char * const argv[], const char *optstring);
60+
#ifndef __CPROVER_GETOPT_H_INCLUDED
61+
#include <getopt.h>
62+
#define __CPROVER_GETOPT_H_INCLUDED
63+
#endif
5764

58-
inline int getopt_long(int argc, char * const argv[], const char *optstring,
59-
const struct option *longopts, int *longindex)
65+
inline int getopt_long(
66+
int argc,
67+
char * const argv[],
68+
const char *optstring,
69+
const struct option *longopts,
70+
int *longindex)
6071
{
6172
// trigger valid-pointer checks (if enabled), even though we don't
6273
// use the parameter in this model

src/ansi-c/library/inet.c

+9-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
#include <arpa/inet.h>
44

5+
in_addr_t __VERIFIER_nondet_in_addr_t();
6+
57
in_addr_t inet_addr(const char *cp)
68
{
79
__CPROVER_HIDE:;
@@ -10,12 +12,14 @@ in_addr_t inet_addr(const char *cp)
1012
__CPROVER_assert(__CPROVER_is_zero_string(cp), "inet_addr zero-termination of argument");
1113
#endif
1214

13-
in_addr_t result;
15+
in_addr_t result=__VERIFIER_nondet_in_addr_t();
1416
return result;
1517
}
1618

1719
/* FUNCTION: inet_aton */
1820

21+
int __VERIFIER_nondet_int();
22+
1923
int inet_aton(const char *cp, struct in_addr *pin)
2024
{
2125
__CPROVER_HIDE:;
@@ -25,12 +29,14 @@ int inet_aton(const char *cp, struct in_addr *pin)
2529
__CPROVER_assert(__CPROVER_is_zero_string(cp), "inet_aton zero-termination of name argument");
2630
#endif
2731

28-
int result;
32+
int result=__VERIFIER_nondet_int();
2933
return result;
3034
}
3135

3236
/* FUNCTION: inet_network */
3337

38+
in_addr_t __VERIFIER_nondet_in_addr_t();
39+
3440
in_addr_t inet_network(const char *cp)
3541
{
3642
__CPROVER_HIDE:;
@@ -39,6 +45,6 @@ in_addr_t inet_network(const char *cp)
3945
__CPROVER_assert(__CPROVER_is_zero_string(cp), "inet_network zero-termination of name argument");
4046
#endif
4147

42-
in_addr_t result;
48+
in_addr_t result=__VERIFIER_nondet_in_addr_t();
4349
return result;
4450
}

0 commit comments

Comments
 (0)