[PATCH] [Static Analyzer] Fix Analysis being skipped for code with declarations in .h file
Karthik Bhat
kv.bhat at samsung.com
Tue Jun 23 00:21:20 PDT 2015
Hi Anna,
Thanks for the review. Please find the updated code as per review comments.
Please let me know if this looks good to you.
Thanks and Regards
Karthik Bhat
http://reviews.llvm.org/D10156
Files:
lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
test/Analysis/test-include.c
test/Analysis/test-include.h
Index: lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
===================================================================
--- lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
+++ lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
@@ -589,9 +589,18 @@
// - System headers: don't run any checks.
SourceManager &SM = Ctx->getSourceManager();
SourceLocation SL = SM.getExpansionLoc(D->getLocation());
+
+ // Check if the definition of the function declaration has a body.
+ // Update the location if function body is found.
+ if (D->hasBody())
+ SL = D->getBody()->getLocStart();
+
if (!Opts->AnalyzeAll && !SM.isWrittenInMainFile(SL)) {
if (SL.isInvalid() || SM.isInSystemHeader(SL))
return AM_None;
+ // Return the current analysis mode if the location is in the main file.
+ if (SM.isInMainFile(SL))
+ return Mode;
return Mode & ~AM_Path;
}
Index: test/Analysis/test-include.c
===================================================================
--- test/Analysis/test-include.c
+++ test/Analysis/test-include.c
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -analyze -analyzer-checker=core -verify %s
+#include "test-include.h"
+void test(int * data) {
+ data = 0;
+ *data = 1; // expected-warning{{Dereference of null pointer}}
+}
Index: test/Analysis/test-include.h
===================================================================
--- test/Analysis/test-include.h
+++ test/Analysis/test-include.h
@@ -0,0 +1 @@
+void test(int * data);
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D10156.28201.patch
Type: text/x-patch
Size: 1483 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150623/be30ee5a/attachment.bin>
More information about the cfe-commits
mailing list