[cfe-commits] r154013 - in /cfe/trunk: lib/CodeGen/CGBlocks.cpp test/CodeGenCXX/block.cpp

David Chisnall csdavec at swan.ac.uk
Wed Apr 4 06:07:13 PDT 2012


Author: theraven
Date: Wed Apr  4 08:07:13 2012
New Revision: 154013

URL: http://llvm.org/viewvc/llvm-project?rev=154013&view=rev
Log:
Don't crash (assert failure) when generating blocks for C++ types with a non-const copy constructor.

This was caused by the code deciding the number of fields in the byref structure using a different test to the part of the code creating the GEPs into said structure.  


Added:
    cfe/trunk/test/CodeGenCXX/block.cpp
Modified:
    cfe/trunk/lib/CodeGen/CGBlocks.cpp

Modified: cfe/trunk/lib/CodeGen/CGBlocks.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBlocks.cpp?rev=154013&r1=154012&r2=154013&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGBlocks.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBlocks.cpp Wed Apr  4 08:07:13 2012
@@ -1850,7 +1850,8 @@
   // int32_t __size;
   types.push_back(Int32Ty);
 
-  bool HasCopyAndDispose = getContext().BlockRequiresCopying(Ty);
+  bool HasCopyAndDispose =
+       (Ty->isObjCRetainableType()) || getContext().getBlockVarCopyInits(D);
   if (HasCopyAndDispose) {
     /// void *__copy_helper;
     types.push_back(Int8PtrTy);

Added: cfe/trunk/test/CodeGenCXX/block.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/block.cpp?rev=154013&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenCXX/block.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/block.cpp Wed Apr  4 08:07:13 2012
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 %s -emit-llvm -o - -fblocks 
+// Just test that this doesn't crash the compiler...
+
+void func(void*);
+
+struct Test
+{
+  virtual void use() { func((void*)this); }
+  Test(Test&c) { func((void*)this); }
+  Test() { func((void*)this); }
+};
+
+void useBlock(void (^)(void));
+
+int main (void) {
+  __block Test t;
+  useBlock(^(void) { t.use(); });
+}
+





More information about the cfe-commits mailing list