Skip to content

Commit 8b0ea48

Browse files
[Clang][CUDA] Disable diagnostics for neon attrs for GPU-side CUDA compilation
Disable diagnostics for neon attributes for GPU-side CUDA compilation. Test plan: ninja check-all Differential revision: https://reviews.llvm.org/D152403
1 parent dcbbdbe commit 8b0ea48

File tree

2 files changed

+35
-5
lines changed

2 files changed

+35
-5
lines changed

clang/lib/Sema/SemaType.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8169,19 +8169,27 @@ static bool verifyValidIntegerConstantExpr(Sema &S, const ParsedAttr &Attr,
81698169
/// match one of the standard Neon vector types.
81708170
static void HandleNeonVectorTypeAttr(QualType &CurType, const ParsedAttr &Attr,
81718171
Sema &S, VectorType::VectorKind VecKind) {
8172+
bool IsTargetCUDAAndHostARM = false;
8173+
if (S.getLangOpts().CUDAIsDevice) {
8174+
const TargetInfo *AuxTI = S.getASTContext().getAuxTargetInfo();
8175+
IsTargetCUDAAndHostARM =
8176+
AuxTI && (AuxTI->getTriple().isAArch64() || AuxTI->getTriple().isARM());
8177+
}
8178+
81728179
// Target must have NEON (or MVE, whose vectors are similar enough
81738180
// not to need a separate attribute)
8174-
if (!S.Context.getTargetInfo().hasFeature("neon") &&
8175-
!S.Context.getTargetInfo().hasFeature("mve")) {
8181+
if (!(S.Context.getTargetInfo().hasFeature("neon") ||
8182+
S.Context.getTargetInfo().hasFeature("mve") ||
8183+
IsTargetCUDAAndHostARM)) {
81768184
S.Diag(Attr.getLoc(), diag::err_attribute_unsupported)
81778185
<< Attr << "'neon' or 'mve'";
81788186
Attr.setInvalid();
81798187
return;
81808188
}
81818189
// Check the attribute arguments.
81828190
if (Attr.getNumArgs() != 1) {
8183-
S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << Attr
8184-
<< 1;
8191+
S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments)
8192+
<< Attr << 1;
81858193
Attr.setInvalid();
81868194
return;
81878195
}
@@ -8191,7 +8199,8 @@ static void HandleNeonVectorTypeAttr(QualType &CurType, const ParsedAttr &Attr,
81918199
return;
81928200

81938201
// Only certain element types are supported for Neon vectors.
8194-
if (!isPermittedNeonBaseType(CurType, VecKind, S)) {
8202+
if (!isPermittedNeonBaseType(CurType, VecKind, S) &&
8203+
!IsTargetCUDAAndHostARM) {
81958204
S.Diag(Attr.getLoc(), diag::err_attribute_invalid_vector_type) << CurType;
81968205
Attr.setInvalid();
81978206
return;

clang/test/SemaCUDA/neon-attrs.cu

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// CPU-side compilation on ARM with neon enabled (no errors expected).
2+
// RUN: %clang_cc1 -triple arm64-linux-gnu -target-feature +neon -aux-triple nvptx64 -x cuda -fsyntax-only -verify=quiet %s
3+
4+
// CPU-side compilation on ARM with neon disabled.
5+
// RUN: %clang_cc1 -triple arm64-linux-gnu -target-feature -neon -aux-triple nvptx64 -x cuda -fsyntax-only -verify %s
6+
7+
// GPU-side compilation on ARM (no errors expected).
8+
// RUN: %clang_cc1 -triple nvptx64 -aux-triple arm64-linux-gnu -fcuda-is-device -x cuda -fsyntax-only -verify=quiet %s
9+
10+
// Regular C++ compilation on ARM with neon enabled (no errors expected).
11+
// RUN: %clang_cc1 -triple arm64-linux-gnu -target-feature +neon -x c++ -fsyntax-only -verify=quiet %s
12+
13+
// Regular C++ compilation on ARM with neon disabled.
14+
// RUN: %clang_cc1 -triple arm64-linux-gnu -target-feature -neon -x c++ -fsyntax-only -verify %s
15+
16+
// quiet-no-diagnostics
17+
typedef __attribute__((neon_vector_type(4))) float float32x4_t;
18+
// expected-error@-1 {{'neon_vector_type' attribute is not supported on targets missing 'neon' or 'mve'}}
19+
typedef unsigned char poly8_t;
20+
typedef __attribute__((neon_polyvector_type(8))) poly8_t poly8x8_t;
21+
// expected-error@-1 {{'neon_polyvector_type' attribute is not supported on targets missing 'neon' or 'mve'}}

0 commit comments

Comments
 (0)