jfb updated this revision to Diff 186752.
jfb added a comment.

- Check for references when looking for copyexpr directly.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D58164/new/

https://reviews.llvm.org/D58164

Files:
  lib/CodeGen/CGBlocks.cpp
  test/CodeGenCXX/lambda-capturing-block.cpp


Index: test/CodeGenCXX/lambda-capturing-block.cpp
===================================================================
--- /dev/null
+++ test/CodeGenCXX/lambda-capturing-block.cpp
@@ -0,0 +1,30 @@
+// RUN: %clang_cc1 -triple=x86_64-apple-darwin -S -emit-llvm -std=c++17 
-fblocks -fcxx-exceptions -o - %s | FileCheck %s
+
+extern "C" {
+
+struct derp {
+    derp() {}
+    derp(const derp& _Src) {}
+    derp(derp&& _Src) {}
+    ~derp() {}
+    void cancel() const{}
+};
+
+// CHECK-LABEL: test(
+void test() {
+  derp c;      
+  auto b = [&](auto const& func) noexcept {
+    auto block = ^() {
+      try {
+        func();
+      } catch (...) {
+        c.cancel();
+      }
+    };
+    block();
+  };
+       
+  b([](){});
+}
+
+}
Index: lib/CodeGen/CGBlocks.cpp
===================================================================
--- lib/CodeGen/CGBlocks.cpp
+++ lib/CodeGen/CGBlocks.cpp
@@ -622,7 +622,7 @@
       }
 
     // So do types that require non-trivial copy construction.
-    } else if (CI.hasCopyExpr()) {
+    } else if (CI.hasCopyExpr() && VT->getAsCXXRecordDecl()) {
       info.NeedsCopyDispose = true;
       info.HasCXXObject = true;
       if (!VT->getAsCXXRecordDecl()->isExternallyVisible())


Index: test/CodeGenCXX/lambda-capturing-block.cpp
===================================================================
--- /dev/null
+++ test/CodeGenCXX/lambda-capturing-block.cpp
@@ -0,0 +1,30 @@
+// RUN: %clang_cc1 -triple=x86_64-apple-darwin -S -emit-llvm -std=c++17 -fblocks -fcxx-exceptions -o - %s | FileCheck %s
+
+extern "C" {
+
+struct derp {
+    derp() {}
+    derp(const derp& _Src) {}
+    derp(derp&& _Src) {}
+    ~derp() {}
+    void cancel() const{}
+};
+
+// CHECK-LABEL: test(
+void test() {
+  derp c;	
+  auto b = [&](auto const& func) noexcept {
+    auto block = ^() {
+      try {
+        func();
+      } catch (...) {
+        c.cancel();
+      }
+    };
+    block();
+  };
+	
+  b([](){});
+}
+
+}
Index: lib/CodeGen/CGBlocks.cpp
===================================================================
--- lib/CodeGen/CGBlocks.cpp
+++ lib/CodeGen/CGBlocks.cpp
@@ -622,7 +622,7 @@
       }
 
     // So do types that require non-trivial copy construction.
-    } else if (CI.hasCopyExpr()) {
+    } else if (CI.hasCopyExpr() && VT->getAsCXXRecordDecl()) {
       info.NeedsCopyDispose = true;
       info.HasCXXObject = true;
       if (!VT->getAsCXXRecordDecl()->isExternallyVisible())
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to