]> granicus.if.org Git - clang/commitdiff
[analyzer] Fix a crash in templated code which uses blocks.
authorAnna Zaks <ganna@apple.com>
Mon, 14 May 2012 22:38:24 +0000 (22:38 +0000)
committerAnna Zaks <ganna@apple.com>
Mon, 14 May 2012 22:38:24 +0000 (22:38 +0000)
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

include/clang/AST/RecursiveASTVisitor.h
test/Analysis/templates.cpp [new file with mode: 0644]

index 41a6d8f503decd0207f0e8103e3dd302958903f5..3d502d230fed8aa1541497eae64701b5b59ad929 100644 (file)
@@ -1241,7 +1241,9 @@ bool RecursiveASTVisitor<Derived>::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 (file)
index 0000000..6add18c
--- /dev/null
@@ -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();
+}