[PATCH] [clang-tidy] Static Analyzer checker configuration options passthrough
Gábor Horváth
xazax.hun at gmail.com
Mon Mar 9 04:50:19 PDT 2015
Hi alexfh,
Starting from http://reviews.llvm.org/rL231266 options for individual static analyzer checkers can be specified.
This patch makes it possible to specify static analyzer checker options in clang tidy configuration files.
http://reviews.llvm.org/D8164
Files:
clang-tidy/ClangTidy.cpp
test/clang-tidy/static-analyzer-config.cpp
Index: clang-tidy/ClangTidy.cpp
===================================================================
--- clang-tidy/ClangTidy.cpp
+++ clang-tidy/ClangTidy.cpp
@@ -204,6 +204,22 @@
}
}
+static void getStaticAnalyzerCheckerOpts(AnalyzerOptionsRef AnalyzerOptions,
+ const ClangTidyOptions &Opts) {
+ StringRef AnalyzerPrefix(AnalyzerCheckNamePrefix);
+ size_t Pos;
+ for (auto &Opt : Opts.CheckOptions) {
+ StringRef OptName(Opt.first);
+ Pos = OptName.rfind('.');
+ if (Pos == StringRef::npos || !OptName.startswith(AnalyzerPrefix))
+ continue;
+ StringRef AnalyzerCheckName =
+ OptName.substr(AnalyzerPrefix.size(), Pos - AnalyzerPrefix.size());
+ AnalyzerOptions->Config[(Twine(AnalyzerCheckName) + ":" +
+ OptName.substr(Pos + 1)).str()] = Opt.second;
+ }
+}
+
std::unique_ptr<clang::ASTConsumer>
ClangTidyASTConsumerFactory::CreateASTConsumer(
clang::CompilerInstance &Compiler, StringRef File) {
@@ -241,6 +257,7 @@
GlobList &Filter = Context.getChecksFilter();
AnalyzerOptions->CheckersControlList = getCheckersControlList(Filter);
if (!AnalyzerOptions->CheckersControlList.empty()) {
+ getStaticAnalyzerCheckerOpts(AnalyzerOptions, Context.getOptions());
AnalyzerOptions->AnalysisStoreOpt = RegionStoreModel;
AnalyzerOptions->AnalysisDiagOpt = PD_NONE;
AnalyzerOptions->AnalyzeNestedBlocks = true;
Index: test/clang-tidy/static-analyzer-config.cpp
===================================================================
--- test/clang-tidy/static-analyzer-config.cpp
+++ test/clang-tidy/static-analyzer-config.cpp
@@ -0,0 +1,19 @@
+// RUN: clang-tidy %s -checks='-*,clang-analyzer-unix.Malloc' -config="{CheckOptions: [{ key: clang-analyzer-unix.Malloc.Optimistic, value: true}]}" -- | FileCheck %s
+typedef __typeof(sizeof(int)) size_t;
+void *malloc(size_t);
+void free(void *);
+void __attribute((ownership_returns(malloc))) *my_malloc(size_t);
+void __attribute((ownership_takes(malloc, 1))) my_free(void *);
+
+void f1() {
+ void *p = malloc(12);
+ return;
+ // CHECK: warning: Potential leak of memory pointed to by 'p' [clang-analyzer-unix.Malloc]
+}
+
+void af2() {
+ void *p = my_malloc(12);
+ my_free(p);
+ free(p);
+ // CHECK: warning: Attempt to free released memory [clang-analyzer-unix.Malloc]
+}
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D8164.21479.patch
Type: text/x-patch
Size: 2359 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150309/a81ed101/attachment.bin>
More information about the cfe-commits
mailing list