Skip to content

Commit 564e082

Browse files
author
Ahsan Saghir
committed
[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
1 parent e76689e commit 564e082

File tree

2 files changed

+37
-7
lines changed

2 files changed

+37
-7
lines changed

clang/lib/Sema/SemaChecking.cpp

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7527,13 +7527,23 @@ bool Sema::SemaBuiltinPPCMMACall(CallExpr *TheCall, unsigned BuiltinID,
75277527
}
75287528

75297529
Expr *Arg = TheCall->getArg(ArgNum);
7530-
QualType ArgType = Arg->getType();
7531-
7532-
if ((ExpectedType->isVoidPointerType() && !ArgType->isPointerType()) ||
7533-
(!ExpectedType->isVoidPointerType() &&
7534-
ArgType.getCanonicalType() != ExpectedType))
7535-
return Diag(Arg->getBeginLoc(), diag::err_typecheck_convert_incompatible)
7536-
<< ArgType << ExpectedType << 1 << 0 << 0;
7530+
QualType PassedType = Arg->getType();
7531+
QualType StrippedRVType = PassedType.getCanonicalType();
7532+
7533+
// Strip Restrict/Volatile qualifiers.
7534+
if (StrippedRVType.isRestrictQualified() ||
7535+
StrippedRVType.isVolatileQualified())
7536+
StrippedRVType = StrippedRVType.getCanonicalType().getUnqualifiedType();
7537+
7538+
// The only case where the argument type and expected type are allowed to
7539+
// mismatch is if the argument type is a non-void pointer and expected type
7540+
// is a void pointer.
7541+
if (StrippedRVType != ExpectedType)
7542+
if (!(ExpectedType->isVoidPointerType() &&
7543+
StrippedRVType->isPointerType()))
7544+
return Diag(Arg->getBeginLoc(),
7545+
diag::err_typecheck_convert_incompatible)
7546+
<< PassedType << ExpectedType << 1 << 0 << 0;
75377547

75387548
// If the value of the Mask is not 0, we have a constraint in the size of
75397549
// the integer argument so here we ensure the argument is a constant that

clang/test/Sema/ppc-pair-mma-types.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,3 +336,23 @@ void testBuiltinTypes3(vector int v, __vector_pair *vp2, signed long l, unsigned
336336
__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 *'}}
337337
__builtin_vsx_stxvp(vp, l, s); // expected-error {{passing 'unsigned short' to parameter of incompatible type 'const __vector_pair *'}}
338338
}
339+
340+
void testRestrictQualifiedPointer1(int *__restrict acc) {
341+
vector float arr[4];
342+
__builtin_mma_disassemble_acc((void *)arr, acc); // expected-error {{passing 'int *restrict' to parameter of incompatible type '__vector_quad *'}}
343+
}
344+
345+
void testRestrictQualifiedPointer2(__vector_quad *__restrict acc) {
346+
vector float arr[4];
347+
__builtin_mma_disassemble_acc((void *)arr, acc);
348+
}
349+
350+
void testVolatileQualifiedPointer1(int *__volatile acc) {
351+
vector float arr[4];
352+
__builtin_mma_disassemble_acc((void *)arr, acc); // expected-error {{passing 'int *volatile' to parameter of incompatible type '__vector_quad *'}}
353+
}
354+
355+
void testVolatileQualifiedPointer2(__vector_quad *__volatile acc) {
356+
vector float arr[4];
357+
__builtin_mma_disassemble_acc((void *)arr, acc);
358+
}

0 commit comments

Comments
 (0)