summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZhanyong Wan <wan@google.com>2010-10-31 04:22:34 +0000
committerZhanyong Wan <wan@google.com>2010-10-31 04:22:34 +0000
commite4f7df694d015c26487fd66878cdcb2d2de0ae83 (patch)
tree1dcd214e3c313acbd51b464195c7fb80dda078bc
parente6f21e4e6eb6a9cc51885d711ad875dfa99093a6 (diff)
downloadbcm5719-llvm-e4f7df694d015c26487fd66878cdcb2d2de0ae83.tar.gz
bcm5719-llvm-e4f7df694d015c26487fd66878cdcb2d2de0ae83.zip
Make Clang static analyzer skip function template definitions. This fixes Clang PR 8426, 8427, & 8433. Reviewed by Ted Kremenek and Doug Gregor.
llvm-svn: 117853
-rw-r--r--clang/lib/Checker/AnalysisConsumer.cpp6
-rw-r--r--clang/test/Analysis/misc-ps-region-store.cpp47
2 files changed, 51 insertions, 2 deletions
diff --git a/clang/lib/Checker/AnalysisConsumer.cpp b/clang/lib/Checker/AnalysisConsumer.cpp
index f902124613c..e1591a6a649 100644
--- a/clang/lib/Checker/AnalysisConsumer.cpp
+++ b/clang/lib/Checker/AnalysisConsumer.cpp
@@ -211,8 +211,10 @@ void AnalysisConsumer::HandleTranslationUnit(ASTContext &C) {
case Decl::CXXMethod:
case Decl::Function: {
FunctionDecl* FD = cast<FunctionDecl>(D);
-
- if (FD->isThisDeclarationADefinition()) {
+ // We skip function template definitions, as their semantics is
+ // only determined when they are instantiated.
+ if (FD->isThisDeclarationADefinition() &&
+ !FD->isDependentContext()) {
if (!Opts.AnalyzeSpecificFunction.empty() &&
FD->getDeclName().getAsString() != Opts.AnalyzeSpecificFunction)
break;
diff --git a/clang/test/Analysis/misc-ps-region-store.cpp b/clang/test/Analysis/misc-ps-region-store.cpp
index bfa5e5cbb9b..dbdfa772a6b 100644
--- a/clang/test/Analysis/misc-ps-region-store.cpp
+++ b/clang/test/Analysis/misc-ps-region-store.cpp
@@ -159,3 +159,50 @@ int r8375510(R8375510 x, R8375510 y) {
for (; ; x++) { }
}
+// PR8426 -- this used to crash.
+
+void Use(void* to);
+
+template <class T> class Foo {
+ ~Foo();
+ struct Bar;
+ Bar* bar_;
+};
+
+template <class T> Foo<T>::~Foo() {
+ Use(bar_);
+ T::DoSomething();
+ bar_->Work();
+}
+
+// PR8427 -- this used to crash.
+
+class Dummy {};
+
+bool operator==(Dummy, int);
+
+template <typename T>
+class Foo2 {
+ bool Bar();
+};
+
+template <typename T>
+bool Foo2<T>::Bar() {
+ return 0 == T();
+}
+
+// PR8433 -- this used to crash.
+
+template <typename T>
+class Foo3 {
+ public:
+ void Bar();
+ void Baz();
+ T value_;
+};
+
+template <typename T>
+void Foo3<T>::Bar() {
+ Baz();
+ value_();
+}
OpenPOWER on IntegriCloud