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@CA@UTrivial@@@Z"(
-// CHECK: call void @"??R<lambda_0>@?0??test@@YAXXZ@QEBA@UTrivial@@@Z"(
+// CHECK-LABEL: define internal void 
@"?__invoke@<lambda_0>@?0??test@@YAXXZ@CA@UTrivial@@@Z"(
+// CHECK: %unused.capture = alloca %class.anon, align 1
+// CHECK: call void @"??R<lambda_0>@?0??test@@YAXXZ@QEBA@UTrivial@@@Z"(ptr 
noundef nonnull align 1 dereferenceable(1) %unused.capture,
 
-// CHECK: define internal void 
@"??R<lambda_0>@?0??test@@YAXXZ@QEBA@UTrivial@@@Z"(
+// CHECK: define internal void 
@"??R<lambda_0>@?0??test@@YAXXZ@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@CA@H@Z"(
+// CHECK: %unused.capture = alloca %class.anon.0, align 1
+// CHECK: call void @"??R<lambda_1>@?0??test2@@YAXXZ@QEBA@H@Z"(ptr noundef 
nonnull align 1 dereferenceable(1) %unused.capture,
+
+// CHECK: define internal void @"??R<lambda_1>@?0??test2@@YAXXZ@QEBA@H@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())


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@CA@UTrivial@@@Z"(
-// CHECK: call void @"??R<lambda_0>@?0??test@@YAXXZ@QEBA@UTrivial@@@Z"(
+// CHECK-LABEL: define internal void @"?__invoke@<lambda_0>@?0??test@@YAXXZ@CA@UTrivial@@@Z"(
+// CHECK: %unused.capture = alloca %class.anon, align 1
+// CHECK: call void @"??R<lambda_0>@?0??test@@YAXXZ@QEBA@UTrivial@@@Z"(ptr noundef nonnull align 1 dereferenceable(1) %unused.capture,
 
-// CHECK: define internal void @"??R<lambda_0>@?0??test@@YAXXZ@QEBA@UTrivial@@@Z"(
+// CHECK: define internal void @"??R<lambda_0>@?0??test@@YAXXZ@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@CA@H@Z"(
+// CHECK: %unused.capture = alloca %class.anon.0, align 1
+// CHECK: call void @"??R<lambda_1>@?0??test2@@YAXXZ@QEBA@H@Z"(ptr noundef nonnull align 1 dereferenceable(1) %unused.capture,
+
+// CHECK: define internal void @"??R<lambda_1>@?0??test2@@YAXXZ@QEBA@H@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())
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to