From: Zhanyong Wan Date: Sun, 31 Oct 2010 04:22:34 +0000 (+0000) Subject: Make Clang static analyzer skip function template definitions. This fixes Clang... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=739830d278b0a174edc59edcfedaecec53d36e3f;p=clang Make Clang static analyzer skip function template definitions. This fixes Clang PR 8426, 8427, & 8433. Reviewed by Ted Kremenek and Doug Gregor. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@117853 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Checker/AnalysisConsumer.cpp b/lib/Checker/AnalysisConsumer.cpp index f902124613..e1591a6a64 100644 --- a/lib/Checker/AnalysisConsumer.cpp +++ b/lib/Checker/AnalysisConsumer.cpp @@ -211,8 +211,10 @@ void AnalysisConsumer::HandleTranslationUnit(ASTContext &C) { case Decl::CXXMethod: case Decl::Function: { FunctionDecl* FD = cast(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/test/Analysis/misc-ps-region-store.cpp b/test/Analysis/misc-ps-region-store.cpp index bfa5e5cbb9..dbdfa772a6 100644 --- a/test/Analysis/misc-ps-region-store.cpp +++ b/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 Foo { + ~Foo(); + struct Bar; + Bar* bar_; +}; + +template Foo::~Foo() { + Use(bar_); + T::DoSomething(); + bar_->Work(); +} + +// PR8427 -- this used to crash. + +class Dummy {}; + +bool operator==(Dummy, int); + +template +class Foo2 { + bool Bar(); +}; + +template +bool Foo2::Bar() { + return 0 == T(); +} + +// PR8433 -- this used to crash. + +template +class Foo3 { + public: + void Bar(); + void Baz(); + T value_; +}; + +template +void Foo3::Bar() { + Baz(); + value_(); +}