[PATCH] [clang-tidy] Static Analyzer checker configuration options passthrough
Gábor Horváth
xazax.hun at gmail.com
Wed Mar 11 06:48:40 PDT 2015
Changes:
- Renamed the function that sets analyzer checker configuration option and swapped the parameters
- Using the same format for checker options as the -analyzer-config analyzer command-line option.
- Minor code tweaks
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,18 @@
}
}
+static void setStaticAnalyzerCheckerOpts(const ClangTidyOptions &Opts,
+ AnalyzerOptionsRef AnalyzerOptions) {
+ StringRef AnalyzerPrefix(AnalyzerCheckNamePrefix);
+ for (const auto &Opt : Opts.CheckOptions) {
+ StringRef OptName(Opt.first);
+ if (!OptName.startswith(AnalyzerPrefix))
+ continue;
+ StringRef AnalyzerCheckName = OptName.substr(AnalyzerPrefix.size());
+ AnalyzerOptions->Config[AnalyzerCheckName] = Opt.second;
+ }
+}
+
std::unique_ptr<clang::ASTConsumer>
ClangTidyASTConsumerFactory::CreateASTConsumer(
clang::CompilerInstance &Compiler, StringRef File) {
@@ -241,6 +253,7 @@
GlobList &Filter = Context.getChecksFilter();
AnalyzerOptions->CheckersControlList = getCheckersControlList(Filter);
if (!AnalyzerOptions->CheckersControlList.empty()) {
+ setStaticAnalyzerCheckerOpts(Context.getOptions(), AnalyzerOptions);
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.21710.patch
Type: text/x-patch
Size: 2182 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150311/6d0c3488/attachment.bin>
More information about the cfe-commits
mailing list