[clang-tools-extra] r231941 - [clang-tidy] Static Analyzer checker configuration options pass-through.
Gabor Horvath
xazax.hun at gmail.com
Wed Mar 11 10:25:22 PDT 2015
Author: xazax
Date: Wed Mar 11 12:25:22 2015
New Revision: 231941
URL: http://llvm.org/viewvc/llvm-project?rev=231941&view=rev
Log:
[clang-tidy] Static Analyzer checker configuration options pass-through.
Reviewed by: Alexander Kornienko
Differential Revision: http://reviews.llvm.org/D8164
Added:
clang-tools-extra/trunk/test/clang-tidy/static-analyzer-config.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp
Modified: clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp?rev=231941&r1=231940&r2=231941&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/ClangTidy.cpp Wed Mar 11 12:25:22 2015
@@ -204,6 +204,17 @@ ClangTidyASTConsumerFactory::ClangTidyAS
}
}
+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;
+ AnalyzerOptions->Config[OptName.substr(AnalyzerPrefix.size())] = Opt.second;
+ }
+}
+
std::unique_ptr<clang::ASTConsumer>
ClangTidyASTConsumerFactory::CreateASTConsumer(
clang::CompilerInstance &Compiler, StringRef File) {
@@ -241,6 +252,7 @@ ClangTidyASTConsumerFactory::CreateASTCo
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;
Added: clang-tools-extra/trunk/test/clang-tidy/static-analyzer-config.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/static-analyzer-config.cpp?rev=231941&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/static-analyzer-config.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/static-analyzer-config.cpp Wed Mar 11 12:25:22 2015
@@ -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]
+}
More information about the cfe-commits
mailing list