diff --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp index 197a874eb180b..9dd1e860d7b59 100644 --- a/clang/lib/AST/ItaniumMangle.cpp +++ b/clang/lib/AST/ItaniumMangle.cpp @@ -4328,9 +4328,13 @@ void CXXNameMangler::mangleRISCVFixedRVVVectorType( void CXXNameMangler::mangleType(const VectorType *T) { if ((T->getVectorKind() == VectorKind::Neon || T->getVectorKind() == VectorKind::NeonPoly)) { - llvm::Triple Target = getASTContext().getTargetInfo().getTriple(); - llvm::Triple::ArchType Arch = - getASTContext().getTargetInfo().getTriple().getArch(); + const TargetInfo *TI = getASTContext().getLangOpts().isTargetDevice() + ? getASTContext().getAuxTargetInfo() + : &getASTContext().getTargetInfo(); + if (!TI) + TI = &getASTContext().getTargetInfo(); + llvm::Triple Target = TI->getTriple(); + llvm::Triple::ArchType Arch = Target.getArch(); if ((Arch == llvm::Triple::aarch64 || Arch == llvm::Triple::aarch64_be) && !Target.isOSDarwin()) mangleAArch64NeonVectorType(T); diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp index 9d2d41c1c6317..51bcb22f41ee8 100644 --- a/clang/lib/Sema/SemaType.cpp +++ b/clang/lib/Sema/SemaType.cpp @@ -8556,10 +8556,9 @@ static bool isPermittedNeonBaseType(QualType &Ty, VectorKind VecKind, Sema &S) { if (VecKind == VectorKind::NeonPoly) { if (IsPolyUnsigned) { // AArch64 polynomial vectors are unsigned. - return BTy->getKind() == BuiltinType::UChar || - BTy->getKind() == BuiltinType::UShort || - BTy->getKind() == BuiltinType::ULong || - BTy->getKind() == BuiltinType::ULongLong; + auto bitwidth = S.Context.getTypeSize(BTy); + return BTy->isUnsignedInteger() && + (bitwidth == 8 || bitwidth == 16 || bitwidth == 64); } else { // AArch32 polynomial vectors are signed. return BTy->getKind() == BuiltinType::SChar || diff --git a/clang/test/SemaSYCL/neon-polyvector-types.cpp b/clang/test/SemaSYCL/neon-polyvector-types.cpp new file mode 100644 index 0000000000000..0dbd8206fd827 --- /dev/null +++ b/clang/test/SemaSYCL/neon-polyvector-types.cpp @@ -0,0 +1,22 @@ +// Does a run with a SYCL device, where neon polyvector type errors are ignored. +// afterwards compile for the host where neon polyvector type errors aren't ignored + +// polyvector type errors get ignored with SYCL enabled +// RUN: %clang_cc1 %s -fsycl-is-device -triple spir64 -aux-triple arm64-unknown-linux-gnu -target-feature +neon -fsyntax-only -verify=quiet + +// diagnostic for bad_poly32_t +// RUN: %clang_cc1 %s -triple arm64-unknown-linux-gnu -target-feature +neon -fsyntax-only -verify +typedef unsigned char poly8_t; +typedef unsigned short poly16_t; +typedef unsigned long poly64_t; + +typedef unsigned int bad_poly32_t; + +typedef __attribute__((neon_polyvector_type(16))) poly8_t poly8x16_t; +typedef __attribute__((neon_polyvector_type(8))) poly16_t poly16x8_t; +typedef __attribute__((neon_polyvector_type(2))) poly64_t poly64x2_t; + +// this error will get ignored when running SYCL +// quiet-no-diagnostics +typedef __attribute__((neon_polyvector_type(2))) bad_poly32_t bad_poly32x2_t; +// expected-error@-1{{invalid vector element type}}