[clang] 564e082 - [PowerPC] Allow MMA built-ins to accept restrict and volatile qualified pointers

Ahsan Saghir via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 12 06:51:55 PDT 2021


Author: Ahsan Saghir
Date: 2021-10-12T08:51:50-05:00
New Revision: 564e082d0954e0beebfff994ac03471d926cd1d1

URL: https://github.com/llvm/llvm-project/commit/564e082d0954e0beebfff994ac03471d926cd1d1
DIFF: https://github.com/llvm/llvm-project/commit/564e082d0954e0beebfff994ac03471d926cd1d1.diff

LOG: [PowerPC] Allow MMA built-ins to accept restrict and volatile qualified pointers

This patch allows MMA built-ins on PowerPC to accept restrict
and volatile qualified pointers.

Reviewed By: #powerpc, nemanjai

Differential Revision: https://reviews.llvm.org/D106550

Added: 
    

Modified: 
    clang/lib/Sema/SemaChecking.cpp
    clang/test/Sema/ppc-pair-mma-types.c

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 0ee05c9f09a52..4d84606290b4e 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -7527,13 +7527,23 @@ bool Sema::SemaBuiltinPPCMMACall(CallExpr *TheCall, unsigned BuiltinID,
     }
 
     Expr *Arg = TheCall->getArg(ArgNum);
-    QualType ArgType = Arg->getType();
-
-    if ((ExpectedType->isVoidPointerType() && !ArgType->isPointerType()) ||
-        (!ExpectedType->isVoidPointerType() &&
-           ArgType.getCanonicalType() != ExpectedType))
-      return Diag(Arg->getBeginLoc(), diag::err_typecheck_convert_incompatible)
-             << ArgType << ExpectedType << 1 << 0 << 0;
+    QualType PassedType = Arg->getType();
+    QualType StrippedRVType = PassedType.getCanonicalType();
+
+    // Strip Restrict/Volatile qualifiers.
+    if (StrippedRVType.isRestrictQualified() ||
+        StrippedRVType.isVolatileQualified())
+      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.
+    if (StrippedRVType != ExpectedType)
+      if (!(ExpectedType->isVoidPointerType() &&
+            StrippedRVType->isPointerType()))
+        return Diag(Arg->getBeginLoc(),
+                    diag::err_typecheck_convert_incompatible)
+               << PassedType << ExpectedType << 1 << 0 << 0;
 
     // If the value of the Mask is not 0, we have a constraint in the size of
     // the integer argument so here we ensure the argument is a constant that

diff  --git a/clang/test/Sema/ppc-pair-mma-types.c b/clang/test/Sema/ppc-pair-mma-types.c
index 360d597dfaffd..5f259b9780ae2 100644
--- a/clang/test/Sema/ppc-pair-mma-types.c
+++ b/clang/test/Sema/ppc-pair-mma-types.c
@@ -336,3 +336,23 @@ void testBuiltinTypes3(vector int v, __vector_pair *vp2, signed long l, unsigned
   __vector_pair vp = __builtin_vsx_lxvp(l, v); // expected-error {{passing '__vector int' (vector of 4 'int' values) to parameter of incompatible type 'const __vector_pair *'}}
   __builtin_vsx_stxvp(vp, l, s);               // expected-error {{passing 'unsigned short' to parameter of incompatible type 'const __vector_pair *'}}
 }
+
+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 *'}}
+}
+
+void testRestrictQualifiedPointer2(__vector_quad *__restrict acc) {
+  vector float arr[4];
+  __builtin_mma_disassemble_acc((void *)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 *'}}
+}
+
+void testVolatileQualifiedPointer2(__vector_quad *__volatile acc) {
+  vector float arr[4];
+  __builtin_mma_disassemble_acc((void *)arr, acc);
+}


        


More information about the cfe-commits mailing list