Skip to content

Commit ad702e0

Browse files
authored
[AArch64] Extend SVE diagnostics. (#94976)
The SVE diagnostics were guarded by a FD->hasBody() check that prevented the diagnostic from being emitted for code that still triggered the backend crashes that the errors were meant to avoid, because FD->hasBody() returns false for a function that Clang is currently processing. This is not done for the equivalent RISC-V code, and is not needed for AArch64 either, so remove it. Errors were also emitted in the wrong location, errors were emitted at the called function's location, rather than at the caller's, which meant that just removing the FD->hasBody() check resulted in incomprehensible errors. Change this as well. The aarch64-mangle-sve-vectors.cpp test was using -target-feature wrong which was exposed as a result of these changes. Different target features need to be passed in as different -target-feature options. aarch64-targetattr-arch.c has a test_errors() function that needs to be split in two. Now that svundef_s8() is diagnosed for its use of svint8_t, the "needs target feature sve" diagnostic is no longer emitted, but this affects all calls in the same function. To ensure we still check this for its __crc32cd call, move that into a separate function. Fixes #94766.
1 parent 90fd99c commit ad702e0

File tree

6 files changed

+33
-19
lines changed

6 files changed

+33
-19
lines changed

clang/lib/Sema/Sema.cpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -2093,16 +2093,15 @@ void Sema::checkTypeSupport(QualType Ty, SourceLocation Loc, ValueDecl *D) {
20932093
}
20942094

20952095
// Don't allow SVE types in functions without a SVE target.
2096-
if (Ty->isSVESizelessBuiltinType() && FD && FD->hasBody()) {
2096+
if (Ty->isSVESizelessBuiltinType() && FD) {
20972097
llvm::StringMap<bool> CallerFeatureMap;
20982098
Context.getFunctionFeatureMap(CallerFeatureMap, FD);
20992099
if (!Builtin::evaluateRequiredTargetFeatures("sve", CallerFeatureMap)) {
21002100
if (!Builtin::evaluateRequiredTargetFeatures("sme", CallerFeatureMap))
2101-
Diag(D->getLocation(), diag::err_sve_vector_in_non_sve_target) << Ty;
2101+
Diag(Loc, diag::err_sve_vector_in_non_sve_target) << Ty;
21022102
else if (!IsArmStreamingFunction(FD,
21032103
/*IncludeLocallyStreaming=*/true)) {
2104-
Diag(D->getLocation(), diag::err_sve_vector_in_non_streaming_function)
2105-
<< Ty;
2104+
Diag(Loc, diag::err_sve_vector_in_non_streaming_function) << Ty;
21062105
}
21072106
}
21082107
}

clang/test/CodeGen/aarch64-targetattr-arch.c

+6-2
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,18 @@ float16_t test_fp16_on_v9(float16_t x, float16_t y)
2929
return vabdh_f16(x, y);
3030
}
3131

32-
void test_errors()
32+
void test_error1()
3333
{
3434
#ifdef HAS8
3535
// expected-error@+2{{always_inline function '__crc32cd' requires target feature 'crc'}}
3636
#endif
3737
__crc32cd(1, 1);
38+
}
39+
40+
void test_error2()
41+
{
3842
#if defined(HAS8) || defined(HAS81)
39-
// expected-error@+2{{'svundef_s8' needs target feature sve}}
43+
// expected-error@+2{{SVE vector type 'svint8_t' (aka '__SVInt8_t') cannot be used in a target without sve}}
4044
#endif
4145
svundef_s8();
4246
}

clang/test/CodeGen/aarch64_neon_sve_bridge_intrinsics/target.c

+18-10
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,23 @@ void target_svebf16(svbfloat16_t t, bfloat16x8_t m) {
1818
}
1919

2020
void base(int8x16_t n, bfloat16x8_t m) {
21-
// expected-error@+1 {{'svundef_s8' needs target feature sve}}
22-
svset_neonq_s8(svundef_s8(), n); // expected-error {{'svset_neonq_s8' needs target feature sve}}
23-
// expected-error@+1 {{'svundef_s8' needs target feature sve}}
24-
svget_neonq_s8(svundef_s8()); // expected-error {{'svget_neonq_s8' needs target feature sve}}
25-
svdup_neonq_s8(n); // expected-error {{'svdup_neonq_s8' needs target feature sve}}
21+
// expected-error@+3 {{SVE vector type 'svint8_t' (aka '__SVInt8_t') cannot be used in a target without sve}}
22+
// expected-error@+2 {{SVE vector type 'svint8_t' (aka '__SVInt8_t') cannot be used in a target without sve}}
23+
// expected-error@+1 {{SVE vector type 'svint8_t' (aka '__SVInt8_t') cannot be used in a target without sve}}
24+
svset_neonq_s8(svundef_s8(), n);
25+
// expected-error@+2 {{SVE vector type 'svint8_t' (aka '__SVInt8_t') cannot be used in a target without sve}}
26+
// expected-error@+1 {{SVE vector type 'svint8_t' (aka '__SVInt8_t') cannot be used in a target without sve}}
27+
svget_neonq_s8(svundef_s8());
28+
// expected-error@+1 {{SVE vector type 'svint8_t' (aka '__SVInt8_t') cannot be used in a target without sve}}
29+
svdup_neonq_s8(n);
2630

27-
// expected-error@+1 {{'svundef_bf16' needs target feature sve}}
28-
svset_neonq_bf16(svundef_bf16(), m); // expected-error {{'svset_neonq_bf16' needs target feature sve,bf16}}
29-
// expected-error@+1 {{'svundef_bf16' needs target feature sve}}
30-
svget_neonq_bf16(svundef_bf16()); // expected-error {{'svget_neonq_bf16' needs target feature sve,bf16}}
31-
svdup_neonq_bf16(m); // expected-error {{'svdup_neonq_bf16' needs target feature sve,bf16}}
31+
// expected-error@+3 {{SVE vector type 'svbfloat16_t' (aka '__SVBfloat16_t') cannot be used in a target without sve}}
32+
// expected-error@+2 {{SVE vector type 'svbfloat16_t' (aka '__SVBfloat16_t') cannot be used in a target without sve}}
33+
// expected-error@+1 {{SVE vector type 'svbfloat16_t' (aka '__SVBfloat16_t') cannot be used in a target without sve}}
34+
svset_neonq_bf16(svundef_bf16(), m);
35+
// expected-error@+2 {{SVE vector type 'svbfloat16_t' (aka '__SVBfloat16_t') cannot be used in a target without sve}}
36+
// expected-error@+1 {{SVE vector type 'svbfloat16_t' (aka '__SVBfloat16_t') cannot be used in a target without sve}}
37+
svget_neonq_bf16(svundef_bf16());
38+
// expected-error@+1 {{SVE vector type 'svbfloat16_t' (aka '__SVBfloat16_t') cannot be used in a target without sve}}
39+
svdup_neonq_bf16(m);
3240
}

clang/test/CodeGenCXX/aarch64-mangle-sve-vectors.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 3
22
// RUN: %clang_cc1 -fclang-abi-compat=latest -triple aarch64-none-linux-gnu %s -emit-llvm -o - \
3-
// RUN: -target-feature +sve,+bf16 | FileCheck %s
3+
// RUN: -target-feature +sve -target-feature +bf16 | FileCheck %s
44
// RUN: %clang_cc1 -fclang-abi-compat=latest -triple aarch64-none-linux-gnu %s -emit-llvm -o - \
5-
// RUN: -target-feature +sve,+bf16 -fclang-abi-compat=17 | FileCheck %s --check-prefix=COMPAT_17
5+
// RUN: -target-feature +sve -target-feature +bf16 -fclang-abi-compat=17 | FileCheck %s --check-prefix=COMPAT_17
66

77
void f(__SVInt8_t, __SVInt8_t);
88
void f(__SVInt16_t, __SVInt16_t);

clang/test/Sema/aarch64-sme2-sve2p1-diagnostics.c

+3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
// expected-error@+2 {{SVE vector type 'svuint8x2_t' (aka '__clang_svuint8x2_t') cannot be used in a non-streaming function}}
1111
__attribute__((target("+sme2")))
1212
svuint8x2_t sme2_or_sve2p1_intrinsic_test_sme2_invalid(svcount_t png, const uint8_t *rn) {
13+
// expected-error@+4 {{SVE vector type 'svcount_t' (aka '__SVCount_t') cannot be used in a non-streaming function}}
14+
// expected-error@+3 {{SVE vector type 'svuint8x2_t' (aka '__clang_svuint8x2_t') cannot be used in a non-streaming function}}
15+
// expected-error@+2 {{SVE vector type 'svcount_t' (aka '__SVCount_t') cannot be used in a non-streaming function}}
1316
// expected-warning@+1 {{builtin call has undefined behaviour when called from a non-streaming function}}
1417
return svldnt1_u8_x2(png, rn);
1518
}

clang/test/Sema/arm-sve-target.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ void test_var_target3() {
2323

2424
__SVFloat32_t other_ret();
2525
__SVFloat32_t test_ret() { // expected-error {{SVE vector type '__SVFloat32_t' cannot be used in a target without sve}}
26-
return other_ret();
26+
return other_ret(); // expected-error {{SVE vector type '__SVFloat32_t' cannot be used in a target without sve}}
2727
}
2828

2929
__attribute__((target("sve")))

0 commit comments

Comments
 (0)