[PATCH] D132275: [clang] Create alloca to pass into static lambda

Vitaly Buka via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 23 13:53:36 PDT 2022


This revision was automatically updated to reflect the committed changes.
Closed by commit rGb5a9adf1f533: [clang] Create alloca to pass into static lambda (authored by vitalybuka).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132275

Files:
  clang/lib/CodeGen/CGClass.cpp
  clang/test/CodeGenCXX/lambda-to-function-pointer-conversion.cpp


Index: clang/test/CodeGenCXX/lambda-to-function-pointer-conversion.cpp
===================================================================
--- clang/test/CodeGenCXX/lambda-to-function-pointer-conversion.cpp
+++ clang/test/CodeGenCXX/lambda-to-function-pointer-conversion.cpp
@@ -2,10 +2,11 @@
 
 // This code used to cause an assertion failure in EmitDelegateCallArg.
 
-// CHECK: define internal void @"?__invoke@<lambda_0>@?0??test@@YAXXZ at CA@UTrivial@@@Z"(
-// CHECK: call void @"??R<lambda_0>@?0??test@@YAXXZ at QEBA@UTrivial@@@Z"(
+// CHECK-LABEL: define internal void @"?__invoke@<lambda_0>@?0??test@@YAXXZ at CA@UTrivial@@@Z"(
+// CHECK: %unused.capture = alloca %class.anon, align 1
+// CHECK: call void @"??R<lambda_0>@?0??test@@YAXXZ at QEBA@UTrivial@@@Z"(ptr noundef nonnull align 1 dereferenceable(1) %unused.capture,
 
-// CHECK: define internal void @"??R<lambda_0>@?0??test@@YAXXZ at QEBA@UTrivial@@@Z"(
+// CHECK: define internal void @"??R<lambda_0>@?0??test@@YAXXZ at QEBA@UTrivial@@@Z"(ptr noundef nonnull align 1 dereferenceable(1) %this,
 
 struct Trivial {
   int x;
@@ -16,3 +17,15 @@
 void test() {
   fnptr = [](Trivial a){ (void)a; };
 }
+
+// CHECK-LABEL: define internal i32 @"?__invoke@<lambda_1>@?0??test2@@YAXXZ at CA@H at Z"(
+// CHECK: %unused.capture = alloca %class.anon.0, align 1
+// CHECK: call void @"??R<lambda_1>@?0??test2@@YAXXZ at QEBA@H at Z"(ptr noundef nonnull align 1 dereferenceable(1) %unused.capture,
+
+// CHECK: define internal void @"??R<lambda_1>@?0??test2@@YAXXZ at QEBA@H at Z"(ptr noundef nonnull align 1 dereferenceable(1) %this,
+
+Trivial (*fnptr2)(int);
+
+void test2() {
+  fnptr2 = [](int) -> Trivial { return {}; };
+}
Index: clang/lib/CodeGen/CGClass.cpp
===================================================================
--- clang/lib/CodeGen/CGClass.cpp
+++ clang/lib/CodeGen/CGClass.cpp
@@ -2969,9 +2969,10 @@
   // Start building arguments for forwarding call
   CallArgList CallArgs;
 
-  QualType ThisType = getContext().getPointerType(getContext().getRecordType(Lambda));
-  llvm::Value *ThisPtr = llvm::UndefValue::get(getTypes().ConvertType(ThisType));
-  CallArgs.add(RValue::get(ThisPtr), ThisType);
+  QualType LambdaType = getContext().getRecordType(Lambda);
+  QualType ThisType = getContext().getPointerType(LambdaType);
+  Address ThisPtr = CreateMemTemp(LambdaType, "unused.capture");
+  CallArgs.add(RValue::get(ThisPtr.getPointer()), ThisType);
 
   // Add the rest of the parameters.
   for (auto Param : MD->parameters())


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D132275.454953.patch
Type: text/x-patch
Size: 2475 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220823/bb33674c/attachment.bin>


More information about the cfe-commits mailing list