Add new "analyze" command to run clang's static analyzer in a directory

on all C/C++ files.
This commit is contained in:
joerg 2011-08-27 18:35:19 +00:00
parent f4a68476b9
commit ba5a5a1119
6 changed files with 54 additions and 8 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: mi,v 1.949 2011/08/26 21:22:07 dyoung Exp $
# $NetBSD: mi,v 1.950 2011/08/27 18:35:19 joerg Exp $
#
# Note: Don't delete entries from here - mark them as "obsolete" instead,
# unless otherwise stated below.
@ -3739,6 +3739,7 @@
./usr/share/misc/vgrindefs.db base-groff-share share
./usr/share/mk base-util-share
./usr/share/mk/bsd.README base-mk-share share
./usr/share/mk/bsd.clang-analyze.mk base-mk-share share
./usr/share/mk/bsd.crypto.mk base-obsolete obsolete
./usr/share/mk/bsd.dep.mk base-mk-share share
./usr/share/mk/bsd.depall.mk base-obsolete obsolete

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile,v 1.43 2010/08/07 21:50:51 christos Exp $
# $NetBSD: Makefile,v 1.44 2011/08/27 18:35:20 joerg Exp $
# @(#)Makefile 8.1 (Berkeley) 6/8/93
NOOBJ= # defined
@ -6,7 +6,8 @@ NOOBJ= # defined
.include <bsd.own.mk>
.if ${MKSHARE} != "no"
FILES= bsd.README bsd.dep.mk bsd.doc.mk bsd.endian.mk bsd.files.mk \
FILES= bsd.README bsd.clang-analyze.mk bsd.dep.mk bsd.doc.mk \
bsd.endian.mk bsd.files.mk \
bsd.gcc.mk bsd.hostlib.mk bsd.hostprog.mk bsd.inc.mk bsd.info.mk \
bsd.init.mk bsd.ioconf.mk bsd.kernobj.mk bsd.kinc.mk bsd.klinks.mk \
bsd.kmodule.mk bsd.lib.mk bsd.links.mk bsd.man.mk bsd.nls.mk \

View File

@ -0,0 +1,42 @@
# $NetBSD: bsd.clang-analyze.mk,v 1.1 2011/08/27 18:35:20 joerg Exp $
.ifndef CLANG_ANALYZE_SRCS
CLANG_ANALYZE_FLAGS+= -Xclang -analyze \
-Xclang -analyzer-store=region \
-Xclang -analyzer-opt-analyze-nested-blocks \
-Xclang -analyzer-eagerly-assume \
-Xclang -analyzer-checker=core \
-Xclang -analyzer-checker=deadcode \
-Xclang -analyzer-checker=security \
-Xclang -analyzer-checker=unix \
-fsyntax-only
.SUFFIXES: .c .cc .cpp .cxx .C .clang-analyzer
CLANG_ANALYZE_CFLAGS= ${CFLAGS:N-Wa,--fatal-warnings}
CLANG_ANALYZE_CXXFLAGS= ${CXXFLAGS:N-Wa,--fatal-warnings}
.c.clang-analyzer:
${TOOL_CC.clang} ${CLANG_ANALYZE_FLAGS} \
${CLANG_ANALYZE_CFLAGS} ${CPPFLAGS} \
${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} \
${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC}
.cc.clang-analyzer .cpp.clang-analyzer .cxx.clang-analyzer .C.clang-analyzer:
${TOOL_CXX.clang} ${CLANG_ANALYZE_FLAGS} \
${CLANG_ANALYZE_CXXFLAGS} ${CPPFLAGS} \
${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} \
${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC}
CLANG_ANALYZE_SRCS= \
${SRCS:M*.[cC]} ${SRCS:M*.cc} \
${SRCS:M*.cpp} ${SRCS:M*.cxx} \
${DPSRCS:M*.[cC]} ${DPSRCS:M*.cc} \
${DPSRCS:M*.cpp} ${DPSRCS:M*.cxx}
.if !empty(CLANG_ANALYZE_SRCS)
CLANG_ANALYZE_OUTPUT= ${CLANG_ANALYZE_SRCS:R:S,$,.clang-analyzer,}
.endif
analyze: ${CLANG_ANALYZE_OUTPUT}
.endif

View File

@ -1,4 +1,4 @@
# $NetBSD: bsd.lib.mk,v 1.314 2011/04/11 23:03:38 joerg Exp $
# $NetBSD: bsd.lib.mk,v 1.315 2011/08/27 18:35:20 joerg Exp $
# @(#)bsd.lib.mk 8.3 (Berkeley) 4/22/94
.include <bsd.init.mk>
@ -776,5 +776,6 @@ LINKSMODE?= ${LIBMODE}
.include <bsd.inc.mk>
.include <bsd.links.mk>
.include <bsd.dep.mk>
.include <bsd.clang-analyze.mk>
${TARGETS}: # ensure existence

View File

@ -1,4 +1,4 @@
# $NetBSD: bsd.own.mk,v 1.680 2011/08/25 00:01:25 uwe Exp $
# $NetBSD: bsd.own.mk,v 1.681 2011/08/27 18:35:20 joerg Exp $
# This needs to be before bsd.init.mk
.if defined(BSD_MK_COMPAT_FILE)
@ -691,11 +691,11 @@ RUMPKMOD= # defined
.endif
TARGETS+= all clean cleandir depend dependall includes \
install lint obj regress tags html
install lint obj regress tags html analyze
PHONY_NOTMAIN = all clean cleandir depend dependall distclean includes \
install lint obj regress beforedepend afterdepend \
beforeinstall afterinstall realinstall realdepend realall \
html subdir-all subdir-install subdir-depend
html subdir-all subdir-install subdir-depend analyze
.PHONY: ${PHONY_NOTMAIN}
.NOTMAIN: ${PHONY_NOTMAIN}

View File

@ -1,4 +1,4 @@
# $NetBSD: bsd.prog.mk,v 1.265 2011/04/26 08:22:17 he Exp $
# $NetBSD: bsd.prog.mk,v 1.266 2011/08/27 18:35:20 joerg Exp $
# @(#)bsd.prog.mk 8.2 (Berkeley) 4/2/94
.ifndef HOSTPROG
@ -475,6 +475,7 @@ LINKSMODE?= ${BINMODE}
.include <bsd.links.mk>
.include <bsd.sys.mk>
.include <bsd.dep.mk>
.include <bsd.clang-analyze.mk>
cleanextra: .PHONY
.if defined(CLEANFILES) && !empty(CLEANFILES)