[PATCH] D151515: [CodeGen] add additional cast when checking call arguments

Congcong Cai via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri May 26 23:50:33 PDT 2023


HerrCai0907 updated this revision to Diff 526245.
HerrCai0907 added a comment.

add cast


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151515

Files:
  clang/lib/Sema/SemaInit.cpp
  clang/test/CodeGenCXX/cxx20-p0388-unbound-ary.cpp


Index: clang/test/CodeGenCXX/cxx20-p0388-unbound-ary.cpp
===================================================================
--- clang/test/CodeGenCXX/cxx20-p0388-unbound-ary.cpp
+++ clang/test/CodeGenCXX/cxx20-p0388-unbound-ary.cpp
@@ -23,4 +23,13 @@
 
   return r2;
 }
+
+// CHECK-LABEL: @_ZN3One3fooEi
+// CHECK-NEXT: entry:
+// CHECK-NEXT: ret void
+void foo(int a) {
+  auto f = [](int(&&)[]) {};
+  f({a});
+}
+
 } // namespace One
Index: clang/lib/Sema/SemaInit.cpp
===================================================================
--- clang/lib/Sema/SemaInit.cpp
+++ clang/lib/Sema/SemaInit.cpp
@@ -4423,6 +4423,15 @@
       if (T1Quals.hasAddressSpace())
         Sequence.AddQualificationConversionStep(
             cv1T1, DestType->isRValueReferenceType() ? VK_XValue : VK_LValue);
+      else if (S.getLangOpts().CPlusPlus20 &&
+               isa<IncompleteArrayType>(T1->getUnqualifiedDesugaredType()) &&
+               DestType->isRValueReferenceType()) {
+        // [dcl.init.list] p3.10
+        // unless T is “reference to array of unknown bound of U”, in which case
+        // the type of the prvalue is the type of x in the declaration U x[] H,
+        // where H is the initializer list.
+        Sequence.AddQualificationConversionStep(cv1T1, VK_XValue);
+      }
     } else
       Sequence.SetFailed(
           InitializationSequence::FK_NonConstLValueReferenceBindingToTemporary);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D151515.526245.patch
Type: text/x-patch
Size: 1419 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230527/3bc376d8/attachment.bin>


More information about the cfe-commits mailing list