tech-toolchain archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Support for clang's static analyzer



Hi all,
attached is a patch to add the "analyze" command. It requires clang and
uses a set of default checkers for all C and C++ source files.

Joerg
Index: distrib/sets/lists/base/mi
===================================================================
RCS file: /home/joerg/repo/netbsd/src/distrib/sets/lists/base/mi,v
retrieving revision 1.948
diff -u -p -r1.948 mi
--- distrib/sets/lists/base/mi  25 Aug 2011 15:29:04 -0000      1.948
+++ distrib/sets/lists/base/mi  25 Aug 2011 18:15:50 -0000
@@ -3738,6 +3738,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
Index: share/mk/Makefile
===================================================================
RCS file: /home/joerg/repo/netbsd/src/share/mk/Makefile,v
retrieving revision 1.43
diff -u -p -r1.43 Makefile
--- share/mk/Makefile   7 Aug 2010 21:50:51 -0000       1.43
+++ share/mk/Makefile   25 Aug 2011 14:04:14 -0000
@@ -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 \
Index: share/mk/bsd.clang-analyze.mk
===================================================================
RCS file: share/mk/bsd.clang-analyze.mk
diff -N share/mk/bsd.clang-analyze.mk
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ share/mk/bsd.clang-analyze.mk       25 Aug 2011 14:14:27 -0000
@@ -0,0 +1,42 @@
+# $NetBSD$
+
+.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
Index: share/mk/bsd.lib.mk
===================================================================
RCS file: /home/joerg/repo/netbsd/src/share/mk/bsd.lib.mk,v
retrieving revision 1.314
diff -u -p -r1.314 bsd.lib.mk
--- share/mk/bsd.lib.mk 11 Apr 2011 23:03:38 -0000      1.314
+++ share/mk/bsd.lib.mk 25 Aug 2011 00:30:28 -0000
@@ -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
Index: share/mk/bsd.own.mk
===================================================================
RCS file: /home/joerg/repo/netbsd/src/share/mk/bsd.own.mk,v
retrieving revision 1.680
diff -u -p -r1.680 bsd.own.mk
--- share/mk/bsd.own.mk 25 Aug 2011 00:01:25 -0000      1.680
+++ share/mk/bsd.own.mk 25 Aug 2011 14:16:06 -0000
@@ -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}
 
Index: share/mk/bsd.prog.mk
===================================================================
RCS file: /home/joerg/repo/netbsd/src/share/mk/bsd.prog.mk,v
retrieving revision 1.265
diff -u -p -r1.265 bsd.prog.mk
--- share/mk/bsd.prog.mk        26 Apr 2011 08:22:17 -0000      1.265
+++ share/mk/bsd.prog.mk        25 Aug 2011 00:30:40 -0000
@@ -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)


Home | Main Index | Thread Index | Old Index