From: Anna Zaks Date: Mon, 14 May 2012 22:38:24 +0000 (+0000) Subject: [analyzer] Fix a crash in templated code which uses blocks. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=45246a7fc00f07bba9a34a3f13c0af72a05f95be;p=clang [analyzer] Fix a crash in templated code which uses blocks. We should investigate why signature info is not set in this case. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@156784 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/RecursiveASTVisitor.h b/include/clang/AST/RecursiveASTVisitor.h index 41a6d8f503..3d502d230f 100644 --- a/include/clang/AST/RecursiveASTVisitor.h +++ b/include/clang/AST/RecursiveASTVisitor.h @@ -1241,7 +1241,9 @@ bool RecursiveASTVisitor::Traverse##DECL (DECL *D) { \ DEF_TRAVERSE_DECL(AccessSpecDecl, { }) DEF_TRAVERSE_DECL(BlockDecl, { - TRY_TO(TraverseTypeLoc(D->getSignatureAsWritten()->getTypeLoc())); + TypeSourceInfo *TInfo = D->getSignatureAsWritten(); + if (TInfo) + TRY_TO(TraverseTypeLoc(TInfo->getTypeLoc())); TRY_TO(TraverseStmt(D->getBody())); // This return statement makes sure the traversal of nodes in // decls_begin()/decls_end() (done in the DEF_TRAVERSE_DECL macro) diff --git a/test/Analysis/templates.cpp b/test/Analysis/templates.cpp new file mode 100644 index 0000000000..6add18c190 --- /dev/null +++ b/test/Analysis/templates.cpp @@ -0,0 +1,29 @@ +// RUN: %clang_cc1 -analyze -analyzer-checker=core -fblocks -verify %s + +// Do not crash on this templated code which uses a block. +typedef void (^my_block)(void); +static void useBlock(my_block block){} +template class MyClass; +typedef MyClass Mf; + +template +class MyClass +{ +public: + MyClass() {} + MyClass(T a); + void I(); +private: + static const T one; +}; + +template const T MyClass::one = static_cast(1); +template inline MyClass::MyClass(T a){} +template void MyClass::I() { + static MyClass* mPtr = 0; + useBlock(^{ mPtr = new MyClass (MyClass::one); }); +}; +int main(){ + Mf m; + m.I(); +}