[cfe-commits] r156784 - in /cfe/trunk: include/clang/AST/RecursiveASTVisitor.h test/Analysis/templates.cpp
Anna Zaks
ganna at apple.com
Mon May 14 15:38:24 PDT 2012
Author: zaks
Date: Mon May 14 17:38:24 2012
New Revision: 156784
URL: http://llvm.org/viewvc/llvm-project?rev=156784&view=rev
Log:
[analyzer] Fix a crash in templated code which uses blocks.
We should investigate why signature info is not set in this case.
Added:
cfe/trunk/test/Analysis/templates.cpp
Modified:
cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
Modified: cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/RecursiveASTVisitor.h?rev=156784&r1=156783&r2=156784&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/RecursiveASTVisitor.h (original)
+++ cfe/trunk/include/clang/AST/RecursiveASTVisitor.h Mon May 14 17:38:24 2012
@@ -1241,7 +1241,9 @@
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)
Added: cfe/trunk/test/Analysis/templates.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/templates.cpp?rev=156784&view=auto
==============================================================================
--- cfe/trunk/test/Analysis/templates.cpp (added)
+++ cfe/trunk/test/Analysis/templates.cpp Mon May 14 17:38:24 2012
@@ -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 T> class MyClass;
+typedef MyClass<float> Mf;
+
+template<class T>
+class MyClass
+{
+public:
+ MyClass() {}
+ MyClass(T a);
+ void I();
+private:
+ static const T one;
+};
+
+template<class T> const T MyClass<T>::one = static_cast<T>(1);
+template<class T> inline MyClass<T>::MyClass(T a){}
+template<class T> void MyClass<T>::I() {
+ static MyClass<T>* mPtr = 0;
+ useBlock(^{ mPtr = new MyClass<T> (MyClass<T>::one); });
+};
+int main(){
+ Mf m;
+ m.I();
+}
More information about the cfe-commits
mailing list