[clang] [Sema][AArch64] Emit error for mismatched VLs on streaming mode transitions (PR #159131)
Sander de Smalen via cfe-commits
cfe-commits at lists.llvm.org
Fri Sep 19 00:17:02 PDT 2025
================
@@ -0,0 +1,111 @@
+// Case 1: No vscale flags — should only produce warnings
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +bf16 -target-feature +sme -target-feature +sme2 -target-feature +sve -Waarch64-sme-attributes -fsyntax-only -verify=expected-noflags %s
+
+// Case 2: Explicit mismatch in vscale flags — should produce errors for
+// streaming and non-streaming callers
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +bf16 -target-feature +sme -target-feature +sme2 -target-feature +sve -Waarch64-sme-attributes -fsyntax-only -mvscale-min=1 -mvscale-max=1 -mvscale-streaming-min=2 -mvscale-streaming-max=2 -verify=expected-flags %s
+
+void sme_streaming_with_vl_arg(__SVInt8_t a) __arm_streaming { }
+
+__SVInt8_t sme_streaming_returns_vl(void) __arm_streaming { __SVInt8_t r; return r; }
+
+void sme_streaming_compatible_with_vl_arg(__SVInt8_t a) __arm_streaming_compatible { }
+
+__SVInt8_t sme_streaming_compatible_returns_vl(void) __arm_streaming_compatible { __SVInt8_t r; return r; }
+
+void sme_no_streaming_with_vl_arg(__SVInt8_t a) { }
+
+__SVInt8_t sme_no_streaming_returns_vl(void) { __SVInt8_t r; return r; }
+
+
+void sme_no_streaming_calling_streaming_with_vl_args() {
+ __SVInt8_t a;
+ // expected-noflags-warning at +2 {{passing a VL-dependent argument to a function with a different streaming-mode is undefined behaviour when the streaming and non-streaming vector lengths are different at runtime}}
+ // expected-flags-error at +1 {{passing a VL-dependent argument to a function with a different streaming-mode is invalid because the streaming vector length (256 bit) and non-streaming vector length (128 bit) differ}}
+ sme_streaming_with_vl_arg(a);
+}
+
+void sme_no_streaming_calling_streaming_with_return_vl() {
+ // expected-noflags-warning at +2 {{returning a VL-dependent argument from a function with a different streaming-mode is undefined behaviour when the streaming and non-streaming vector lengths are different at runtime}}
+ // expected-flags-error at +1 {{returning a VL-dependent argument from a function with a different streaming-mode is invalid because the streaming vector length (256 bit) and non-streaming vector length (128 bit) differ}}
+ __SVInt8_t r = sme_streaming_returns_vl();
+}
+
+void sme_streaming_calling_non_streaming_with_vl_args(void) __arm_streaming {
+ __SVInt8_t a;
+ // expected-noflags-warning at +2 {{passing a VL-dependent argument to a function with a different streaming-mode is undefined behaviour when the streaming and non-streaming vector lengths are different at runtime}}
+ // expected-flags-error at +1 {{passing a VL-dependent argument to a function with a different streaming-mode is invalid because the streaming vector length (256 bit) and non-streaming vector length (128 bit) differ}}
+ sme_no_streaming_with_vl_arg(a);
+}
+
+void sme_streaming_calling_non_streaming_with_return_vl(void) __arm_streaming {
+ // expected-noflags-warning at +2 {{returning a VL-dependent argument from a function with a different streaming-mode is undefined behaviour when the streaming and non-streaming vector lengths are different at runtime}}
+ // expected-flags-error at +1 {{returning a VL-dependent argument from a function with a different streaming-mode is invalid because the streaming vector length (256 bit) and non-streaming vector length (128 bit) differ}}
+ __SVInt8_t r = sme_no_streaming_returns_vl();
+}
+
+void sme_streaming_compatible_calling_streaming_with_vl_args(__SVInt8_t arg) __arm_streaming_compatible {
+ // expected-noflags-warning at +2 {{passing a VL-dependent argument to a function with a different streaming-mode is undefined behaviour when the streaming and non-streaming vector lengths are different at runtime}}
+ // expected-flags-warning at +1 {{passing a VL-dependent argument to a streaming-compatible function is undefined behaviour when the callee is in a different streaming mode because the streaming vector length (256 bit) and non-streaming vector length (128 bit) differ}}
+ sme_streaming_with_vl_arg(arg);
+}
+
+void sme_streaming_compatible_calling_sme_streaming_return_vl(void) __arm_streaming_compatible {
+ // expected-noflags-warning at +2 {{returning a VL-dependent argument from a function with a different streaming-mode is undefined behaviour when the streaming and non-streaming vector lengths are different at runtime}}
+ // expected-flags-warning at +1 {{returning a VL-dependent argument from a streaming-compatible function is undefined behaviour when the callee is in a different streaming mode because the streaming vector length (256 bit) and non-streaming vector length (128 bit) differ}}
+ __SVInt8_t r = sme_streaming_returns_vl();
+}
+
+void sme_streaming_compatible_calling_no_streaming_with_vl_args(__SVInt8_t arg) __arm_streaming_compatible {
+ // expected-noflags-warning at +2 {{passing a VL-dependent argument to a function with a different streaming-mode is undefined behaviour when the streaming and non-streaming vector lengths are different at runtime}}
+ // expected-flags-warning at +1 {{passing a VL-dependent argument to a streaming-compatible function is undefined behaviour when the callee is in a different streaming mode because the streaming vector length (256 bit) and non-streaming vector length (128 bit) differ}}
----------------
sdesmalen-arm wrote:
Sorry, I realise this is still not entirely right. The message says "passing an argument to a _streaming-compatible function_ is undefined behaviour [..]", but this is passing an argument to a non-streaming function.
The cases as I see them are:
```
S -> S // always okay, no diagnostic
S -> SC // always okay, no diagnostic
S -> N // undefined behaviour iff SVL != VL (error if this is known, warning if not)
N -> N // always okay, no diagnostic
N -> SC // always okay, no diagnostic
N -> S // undefined behaviour iff SVL != VL (error if this is known, warning if not)
SC -> SC // always okay, no diagnostic
SC -> N // undefined behaviour iff SVL != VL and caller is streaming (could split this out into two different warnings, one generic and one more specific)
SC -> S // undefined behaviour iff SVL != VL and caller is non-streaming (could split this out into two different warnings, one generic and one more specific)
```
I think this PR covers N -> N/SC/S, S -> N/SC/S and SC -> SC correctly, but the SC -> N/S needs subtly different messages.
https://github.com/llvm/llvm-project/pull/159131
More information about the cfe-commits
mailing list