[PATCH] D113306: [PowerPC] Allow MMA built-ins to accept non-void pointers and arrays

Ahsan Saghir via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Nov 5 12:27:11 PDT 2021


saghir created this revision.
Herald added subscribers: shchenz, kbarton, nemanjai.
saghir requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Calls to MMA builtins that take pointer to void
do not accept other pointers/arrays whereas normal
functions with the same parameter do. This patch
allows MMA built-ins to accept non-void pointers
and arrays.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D113306

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/test/Sema/ppc-pair-mma-types.c


Index: clang/test/Sema/ppc-pair-mma-types.c
===================================================================
--- clang/test/Sema/ppc-pair-mma-types.c
+++ clang/test/Sema/ppc-pair-mma-types.c
@@ -339,20 +339,20 @@
 
 void testRestrictQualifiedPointer1(int *__restrict acc) {
   vector float arr[4];
-  __builtin_mma_disassemble_acc((void *)arr, acc); // expected-error {{passing 'int *restrict' to parameter of incompatible type '__vector_quad *'}}
+  __builtin_mma_disassemble_acc(arr, acc); // expected-error {{passing 'int *restrict' to parameter of incompatible type '__vector_quad *'}}
 }
 
 void testRestrictQualifiedPointer2(__vector_quad *__restrict acc) {
   vector float arr[4];
-  __builtin_mma_disassemble_acc((void *)arr, acc);
+  __builtin_mma_disassemble_acc(arr, acc);
 }
 
 void testVolatileQualifiedPointer1(int *__volatile acc) {
   vector float arr[4];
-  __builtin_mma_disassemble_acc((void *)arr, acc); // expected-error {{passing 'int *volatile' to parameter of incompatible type '__vector_quad *'}}
+  __builtin_mma_disassemble_acc(arr, acc); // expected-error {{passing 'int *volatile' to parameter of incompatible type '__vector_quad *'}}
 }
 
 void testVolatileQualifiedPointer2(__vector_quad *__volatile acc) {
   vector float arr[4];
-  __builtin_mma_disassemble_acc((void *)arr, acc);
+  __builtin_mma_disassemble_acc(arr, acc);
 }
Index: clang/lib/Sema/SemaChecking.cpp
===================================================================
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -7431,11 +7431,11 @@
       StrippedRVType = StrippedRVType.getCanonicalType().getUnqualifiedType();
 
     // The only case where the argument type and expected type are allowed to
-    // mismatch is if the argument type is a non-void pointer and expected type
-    // is a void pointer.
+    // mismatch is if the argument type is a non-void pointer (or array) and
+    // expected type is a void pointer.
     if (StrippedRVType != ExpectedType)
       if (!(ExpectedType->isVoidPointerType() &&
-            StrippedRVType->isPointerType()))
+            (StrippedRVType->isPointerType() || StrippedRVType->isArrayType())))
         return Diag(Arg->getBeginLoc(),
                     diag::err_typecheck_convert_incompatible)
                << PassedType << ExpectedType << 1 << 0 << 0;
Index: clang/lib/CodeGen/CGBuiltin.cpp
===================================================================
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -15166,8 +15166,12 @@
                                            const CallExpr *E) {
   SmallVector<Value*, 4> Ops;
 
-  for (unsigned i = 0, e = E->getNumArgs(); i != e; i++)
-    Ops.push_back(EmitScalarExpr(E->getArg(i)));
+  for (unsigned i = 0, e = E->getNumArgs(); i != e; i++) {
+    if (E->getArg(i)->getType()->isArrayType())
+      Ops.push_back(EmitArrayToPointerDecay(E->getArg(i)).getPointer());
+    else
+      Ops.push_back(EmitScalarExpr(E->getArg(i)));
+  }
 
   Intrinsic::ID ID = Intrinsic::not_intrinsic;
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D113306.385150.patch
Type: text/x-patch
Size: 3053 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211105/9dd726ad/attachment.bin>


More information about the cfe-commits mailing list