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

Congcong Cai via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu May 25 16:04:48 PDT 2023


HerrCai0907 created this revision.
HerrCai0907 added reviewers: shafik, erichkeane, aaron.ballman.
Herald added a project: All.
HerrCai0907 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Fixed: https://github.com/llvm/llvm-project/issues/62945
c++20 supports "Permit conversions to arrays of unknown bound".
This make it possible that ConstantArrayType is function parameter
but IncompleteArrayType is argument (initializer list).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151515

Files:
  clang/lib/CodeGen/CGCall.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/CodeGen/CGCall.cpp
===================================================================
--- clang/lib/CodeGen/CGCall.cpp
+++ clang/lib/CodeGen/CGCall.cpp
@@ -4369,14 +4369,19 @@
     CallExpr::const_arg_iterator Arg = ArgRange.begin();
     for (QualType Ty : ArgTypes) {
       assert(Arg != ArgRange.end() && "Running over edge of argument list!");
-      assert(
-          (isGenericMethod || Ty->isVariablyModifiedType() ||
-           Ty.getNonReferenceType()->isObjCRetainableType() ||
-           getContext()
-                   .getCanonicalType(Ty.getNonReferenceType())
-                   .getTypePtr() ==
-               getContext().getCanonicalType((*Arg)->getType()).getTypePtr()) &&
-          "type mismatch in call argument!");
+      // argument can be ConstantArrayType and parameter can be IncompleteArrayType
+      const Type *CanonicalTy = getContext()
+                                    .getCanonicalType(Ty.getNonReferenceType())
+                                    .getTypePtr()
+                                    ->getPointeeOrArrayElementType();
+      const Type *CanonicalArgTy = getContext()
+                                       .getCanonicalType((*Arg)->getType())
+                                       .getTypePtr()
+                                       ->getPointeeOrArrayElementType();
+      assert((isGenericMethod || Ty->isVariablyModifiedType() ||
+              Ty.getNonReferenceType()->isObjCRetainableType() ||
+              CanonicalTy == CanonicalArgTy) &&
+             "type mismatch in call argument!");
       ++Arg;
     }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D151515.525854.patch
Type: text/x-patch
Size: 2045 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230525/a97a065d/attachment.bin>


More information about the cfe-commits mailing list