]> granicus.if.org Git - clang/commitdiff
Don't crash (assert failure) when generating blocks for C++ types with a non-const...
authorDavid Chisnall <csdavec@swan.ac.uk>
Wed, 4 Apr 2012 13:07:13 +0000 (13:07 +0000)
committerDavid Chisnall <csdavec@swan.ac.uk>
Wed, 4 Apr 2012 13:07:13 +0000 (13:07 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@154013 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGBlocks.cpp
test/CodeGenCXX/block.cpp [new file with mode: 0644]

index 9fe31cb9581e27137fcf01e3bd560d8aad74b8ea..09d3125ce81d0fad846312d9d2d9bd2b221bb6c6 100644 (file)
@@ -1850,7 +1850,8 @@ llvm::Type *CodeGenFunction::BuildByRefType(const VarDecl *D) {
   // 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);
diff --git a/test/CodeGenCXX/block.cpp b/test/CodeGenCXX/block.cpp
new file mode 100644 (file)
index 0000000..619d8b0
--- /dev/null
@@ -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(); });
+}
+