From ba5a5a11195dc837d005c7c233f1bd26e2587ef1 Mon Sep 17 00:00:00 2001 From: joerg Date: Sat, 27 Aug 2011 18:35:19 +0000 Subject: [PATCH] Add new "analyze" command to run clang's static analyzer in a directory on all C/C++ files. --- distrib/sets/lists/base/mi | 3 ++- share/mk/Makefile | 5 +++-- share/mk/bsd.clang-analyze.mk | 42 +++++++++++++++++++++++++++++++++++ share/mk/bsd.lib.mk | 3 ++- share/mk/bsd.own.mk | 6 ++--- share/mk/bsd.prog.mk | 3 ++- 6 files changed, 54 insertions(+), 8 deletions(-) create mode 100644 share/mk/bsd.clang-analyze.mk diff --git a/distrib/sets/lists/base/mi b/distrib/sets/lists/base/mi index 1a127f317ca0..549b21e2f69a 100644 --- a/distrib/sets/lists/base/mi +++ b/distrib/sets/lists/base/mi @@ -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 diff --git a/share/mk/Makefile b/share/mk/Makefile index b60dd44775eb..0a98e0797d5f 100644 --- a/share/mk/Makefile +++ b/share/mk/Makefile @@ -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 .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 \ diff --git a/share/mk/bsd.clang-analyze.mk b/share/mk/bsd.clang-analyze.mk new file mode 100644 index 000000000000..23a4d65ef2e2 --- /dev/null +++ b/share/mk/bsd.clang-analyze.mk @@ -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 diff --git a/share/mk/bsd.lib.mk b/share/mk/bsd.lib.mk index 157944f8e4ab..eef337013dbd 100644 --- a/share/mk/bsd.lib.mk +++ b/share/mk/bsd.lib.mk @@ -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 @@ -776,5 +776,6 @@ LINKSMODE?= ${LIBMODE} .include .include .include +.include ${TARGETS}: # ensure existence diff --git a/share/mk/bsd.own.mk b/share/mk/bsd.own.mk index 1bcf91992f45..ff734a9a0565 100644 --- a/share/mk/bsd.own.mk +++ b/share/mk/bsd.own.mk @@ -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} diff --git a/share/mk/bsd.prog.mk b/share/mk/bsd.prog.mk index 769b6712b917..86d3c95583f8 100644 --- a/share/mk/bsd.prog.mk +++ b/share/mk/bsd.prog.mk @@ -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 .include .include +.include cleanextra: .PHONY .if defined(CLEANFILES) && !empty(CLEANFILES)