[PATCH] D132275: [clang] Create alloca to pass into static lambda
Vitaly Buka via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 22 15:09:00 PDT 2022
vitalybuka updated this revision to Diff 454628.
vitalybuka added a comment.
created alloca instead of changing attributes
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 {}; };
+}
\ No newline at end of file
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.454628.patch
Type: text/x-patch
Size: 2503 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220822/f7f9e579/attachment.bin>
More information about the cfe-commits
mailing list