summaryrefslogtreecommitdiff
path: root/src/third_party/wiredtiger/dist/s_clang-scan
blob: 9a5ee3d458759651a7c725fcdf480c7853057b1b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#! /bin/sh

t=__wt.$$
a=__wt.$$.a
b=__wt.$$.b
trap 'rm -rf $a $b $t' 0 1 2 3 13 15

# Find the top-level WiredTiger directory and move to there.
top=`git rev-parse --show-toplevel` && cd $top || exit 1
echo "$0: running scan-build in $PWD"

# Clang isn't installed in any standard place, find a binary we can use.
# If the caller gives us $SCANBUILD, check for $SCANCOMPILER and default
# to "clang".
scan="$SCANBUILD"
test -z "$scan" || compiler="${SCANCOMPILER:-clang}"

if test -z "$scan" &&
    test -x /usr/bin/clang &&
    test -x /usr/bin/scan-build; then
	compiler="/usr/bin/clang"
	scan="/usr/bin/scan-build"
fi

if test -z "$scan"; then
	echo "$0: no clang compiler and scan-build programs found"
	echo "$0: set \$SCANCOMPILER=/path/clang and \$SCANBUILD=/path/scan-build to continue"
	exit 1
fi
echo "$0: compiler: $compiler"
echo "$0: scan-build: $scan"

# Remove old reports.
rm -rf clangScanBuildReports && mkdir clangScanBuildReports

sh autogen.sh > /dev/null || exit 1

args="-o clangScanBuildReports"
args="$args --use-cc=$compiler"
args="$args -disable-checker core.NullDereference"
$scan $args ./configure 'CFLAGS=-g' \
    --disable-shared --enable-diagnostic --enable-strict > /dev/null
$scan $args make -j 8 wt 1>/dev/null 2>$t

make -j 8 distclean > /dev/null

grep 'No bugs found' $t > /dev/null && exit 0

# Compare the set of errors/warnings and exit success when they're expected.
# clang-scan outputs errors/warnings with a leading file path followed by a
# colon, followed by the string "error:" or "warning:".
cat dist/s_clang-scan.diff |
    egrep '^[a-z\./].*error: |^[a-z\./].*warning: ' | sed -e 's/:.*:.*://' | sort > $a
cat $t |
    egrep '^[a-z\./].*error: |^[a-z\./].*warning: ' | sed -e 's/:.*:.*://' | sort > $b
diff $a $b > /dev/null && exit 0

echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-="
echo 'scan-build output differs from expected:'
echo '<<<<<<<<<< Expected >>>>>>>>>> Current'
echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-="
diff dist/s_clang-scan.diff $t
exit 1