Skip to content

Commit 83d3770

Browse files
[Clang][AArch64] Remove unwarranted 'cannot be used in non-streaming mode' diagnostic. (#150592)
Previously Clang would give an unwarranted error on the capture of '&a' in the function below, even though the parent function and the lambda are both `__arm_streaming` functions, when the target is compiled with +sme only. ``` void test_both_streaming(int32_t *out) __arm_streaming { svint32_t a; [&a, &out]() __arm_streaming { ^ error: SVE vector type 'svint32_t' (aka '__SVInt32_t') cannot be used in a non-streaming function a = svdup_s32(1); svst1(svptrue_b32(), out, a); }(); } ``` That seems to happen because when `checkTypeSupport` is called the `FunctionDecl` context of the lambda isn't yet complete and `FD->getType()` returns a Null `QualTy`. This is loosely related to #94976 which removed a `FD->hasBody()` check in the same place, because `hasBody()` may incorrectly return `false` when Clang is still processing a function.
1 parent 8f9b018 commit 83d3770

File tree

2 files changed

+56
-3
lines changed

2 files changed

+56
-3
lines changed

clang/lib/Sema/Sema.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2251,16 +2251,15 @@ void Sema::checkTypeSupport(QualType Ty, SourceLocation Loc, ValueDecl *D) {
22512251
}
22522252

22532253
// Don't allow SVE types in functions without a SVE target.
2254-
if (Ty->isSVESizelessBuiltinType() && FD) {
2254+
if (Ty->isSVESizelessBuiltinType() && FD && !FD->getType().isNull()) {
22552255
llvm::StringMap<bool> CallerFeatureMap;
22562256
Context.getFunctionFeatureMap(CallerFeatureMap, FD);
22572257
if (!Builtin::evaluateRequiredTargetFeatures("sve", CallerFeatureMap)) {
22582258
if (!Builtin::evaluateRequiredTargetFeatures("sme", CallerFeatureMap))
22592259
Diag(Loc, diag::err_sve_vector_in_non_sve_target) << Ty;
22602260
else if (!IsArmStreamingFunction(FD,
2261-
/*IncludeLocallyStreaming=*/true)) {
2261+
/*IncludeLocallyStreaming=*/true))
22622262
Diag(Loc, diag::err_sve_vector_in_non_streaming_function) << Ty;
2263-
}
22642263
}
22652264
}
22662265

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sme -fsyntax-only -verify %s
2+
3+
#include <arm_sme.h>
4+
5+
void test_streaming(svint32_t *out, svint32_t *in) __arm_streaming {
6+
*out = *in;
7+
}
8+
9+
void test_non_streaming(svint32_t *out, svint32_t *in) {
10+
*out = *in; // expected-error {{SVE vector type 'svint32_t' (aka '__SVInt32_t') cannot be used in a non-streaming function}} \
11+
expected-error {{SVE vector type 'svint32_t' (aka '__SVInt32_t') cannot be used in a non-streaming function}}
12+
}
13+
14+
// This previously led to a diagnostic that '&a' could not be used in a non-streaming function,
15+
// even though all functions are streaming.
16+
void test_both_streaming(int32_t *out) __arm_streaming {
17+
svint32_t a;
18+
[&a, &out]() __arm_streaming {
19+
a = svdup_s32(1);
20+
svst1(svptrue_b32(), out, a);
21+
}();
22+
}
23+
24+
void test_lambda_streaming(int32_t *out) {
25+
svint32_t a; // expected-error {{SVE vector type 'svint32_t' (aka '__SVInt32_t') cannot be used in a non-streaming function}}
26+
[&a, &out]() __arm_streaming {
27+
a = 1;
28+
svst1(svptrue_b32(), out, a);
29+
}();
30+
}
31+
32+
void test_lambda_non_streaming_capture_do_nothing() __arm_streaming {
33+
svint32_t a;
34+
[&a] {
35+
// Do nothing.
36+
}();
37+
}
38+
39+
// Error: Non-streaming function attempts to dereference capture:
40+
void test_lambda_non_streaming_capture_return_vector() __arm_streaming {
41+
svint32_t a;
42+
[&a] {
43+
return a; // expected-error {{SVE vector type 'svint32_t' (aka '__SVInt32_t') cannot be used in a non-streaming function}}
44+
}();
45+
}
46+
47+
// By reference capture, only records and uses the address of `a`:
48+
// FIXME: This should be okay.
49+
void test_lambda_non_streaming_capture_return_address() __arm_streaming {
50+
svint32_t a;
51+
[&a] {
52+
return &a; // expected-error {{SVE vector type 'svint32_t' (aka '__SVInt32_t') cannot be used in a non-streaming function}}
53+
}();
54+
}

0 commit comments

Comments
 (0)