Skip to content

Commit 4efb238

Browse files
committed
Disable (and explain) compare-null-against-non-null-parameter warning
1 parent b846858 commit 4efb238

File tree

2 files changed

+32
-14
lines changed

2 files changed

+32
-14
lines changed

src/ansi-c/Makefile

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -91,21 +91,9 @@ ifeq ($(BUILD_ENV),MinGW)
9191
else
9292
platform_unavail = library/java.io.c library/threads.c
9393
endif
94+
9495
library_check: library/*.c
95-
for f in $(filter-out $(platform_unavail), $^) ; do \
96-
echo "Checking $$f" ; \
97-
cp $$f __libcheck.c ; \
98-
perl -p -i -e 's/(__builtin_[^v])/s$$1/' __libcheck.c ; \
99-
perl -p -i -e 's/(__sync_)/s$$1/' __libcheck.c ; \
100-
perl -p -i -e 's/(__noop)/s$$1/' __libcheck.c ; \
101-
$(CC) -std=gnu99 -E -include library/cprover.h -D__CPROVER_bool=_Bool \
102-
-D__CPROVER_thread_local=__thread -DLIBRARY_CHECK -o __libcheck.i __libcheck.c ; \
103-
$(CC) -S -Wall -Werror -pedantic -Wextra -std=gnu99 __libcheck.i -o __libcheck.s \
104-
-Wno-unused-label ; \
105-
ec=$$? ; \
106-
$(RM) __libcheck.s __libcheck.i __libcheck.c ; \
107-
[ $$ec -eq 0 ] || exit $$ec ; \
108-
done
96+
CC=$(CC) RM="$(RM)" ./library_check.sh $(filter-out $(platform_unavail), $^)
10997
touch $@
11098

11199
cprover_library.inc: library/converter$(EXEEXT) library/*.c

src/ansi-c/library_check.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
3+
# Note use of -Wno-nonnull-compare below: functions in string.c (and others) null-check their parameters,
4+
# but some versions of libc tag them non-null, authorising the optimiser to discard those checks.
5+
# This is acceptable to use because this version of the library is only for use by cbmc, which does
6+
# not use the non-null attribute in this way.
7+
# See https://clang.llvm.org/docs/AttributeReference.html#nonnull-gnu-nonnull
8+
9+
if echo "" | "$CC" -Werror -Wno-nonnull-compare -E - >/dev/null 2>&1; then
10+
# Expected option for gcc
11+
DISABLE_NONNULL_WARNING=-Wno-nonnull-compare
12+
elif echo "" | "$CC" -Werror -Wno-tautological-pointer-compare -Wno-pointer-bool-conversion -E - >/dev/null 2>&1; then
13+
# Expected option for clang
14+
DISABLE_NONNULL_WARNING="-Wno-tautological-pointer-compare -Wno-pointer-bool-conversion"
15+
else
16+
echo >&2 "Couldn't find compiler options to disable warnings regarding comparison vs. __nonnull__ pointers, this may cause test failures"
17+
fi
18+
19+
for f in "$@"; do
20+
echo "Checking $f"
21+
cp $f __libcheck.c
22+
perl -p -i -e 's/(__builtin_[^v])/s$1/' __libcheck.c
23+
perl -p -i -e 's/(__sync_)/s$1/' __libcheck.c
24+
perl -p -i -e 's/(__noop)/s$1/' __libcheck.c
25+
"$CC" -std=gnu99 -E -include library/cprover.h -D__CPROVER_bool=_Bool -D__CPROVER_thread_local=__thread -DLIBRARY_CHECK -o __libcheck.i __libcheck.c
26+
"$CC" -S -Wall -Werror -pedantic -Wextra $DISABLE_NONNULL_WARNING -std=gnu99 __libcheck.i -o __libcheck.s -Wno-unused-label
27+
ec=$?
28+
$RM __libcheck.s __libcheck.i __libcheck.c
29+
[ $ec -eq 0 ] || exit $ec
30+
done

0 commit comments

Comments
 (0)