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/
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);
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits