Inconsistent and undocumented placement rules for __arm_streaming vs __arm_locally_streaming
Summary
Clang enforces inconsistent and undocumented syntax placement rules for the SME streaming attributes __arm_streaming and __arm_locally_streaming. Although both apply to functions and control SME streaming mode, one is parsed only as a postfix function attribute while the other is parsed only as a declaration specifier. This asymmetry is surprising, not required by ACLE, and causes real-world usability issues.
Description
When compiling SME-enabled code, Clang accepts the following forms:
__attribute__((target("+sme"))) void ok1(void) __arm_streaming {}
__attribute__((target("+sme"))) __arm_locally_streaming void ok2(void) {}
but rejects these otherwise equivalent forms:
__attribute__((target("+sme"))) __arm_streaming void bad1(void) {}
__attribute__((target("+sme"))) void bad2(void) __arm_locally_streaming {}
I prepared this minimal reproducer in https://github.com/cielavenir/smetest/tree/d24184a3818bd56e045193458e98df495c6e6112 , whose action https://github.com/cielavenir/smetest/actions/runs/21424244895/job/61689869303 says:
test.c:6:33: error: '__arm_streaming' cannot be applied to a declaration
6 | __attribute__((target("+sme"))) __arm_streaming void bad1(void) {}
| ^ ~~~~
test.c:7:49: error: '__arm_locally_streaming' cannot be applied to types
7 | __attribute__((target("+sme"))) void bad2(void) __arm_locally_streaming {}
| ^
2 errors generated.
This behavior is highly unintuitive because:
- Both attributes apply to functions
- Both control SME streaming state
- Neither the Arm ACLE nor Clang documentation specifies asymmetric placement rules
- Other function attributes in Clang generally allow consistent prefix/postfix placement via attribute
Expected Behavior
Either:
- Both attributes accept consistent placement (prefix and/or postfix), or
- Clang emits a clear diagnostic documenting the required placement rules
Actual Behavior
__arm_streamingis accepted only as a postfix function attribute__arm_locally_streamingis accepted only as a declaration specifier
The difference is undocumented and non-obvious
Environment
- Clang: Clang/LLVM (Homebrew) 20.1.8 cf https://github.com/actions/runner-images/blob/main/images/macos/macos-26-arm64-Readme.md
- Target: AArch64, SME enabled
- OS: macOS
This issue is ChatGPT-assisted https://chatgpt.com/share/6979898d-dedc-8008-89c4-f473c7f00e27 (though his minimal reproducer did not work out-of-box and I needed to fix a bit)
ChatGPT also gave some insights (which I have not checked, so these might be wrong):
Implementation Notes
The inconsistency appears to stem from different parsing mechanisms:
__arm_streamingis implemented as a GNU-style postfix function attribute (ArmStreaming in Attr.td)__arm_locally_streamingis implemented as a declaration specifier (DeclSpec::TST_arm_locally_streaming)
This asymmetry is an implementation artifact rather than an architectural requirement.
Impact
This behavior is particularly problematic in real-world SME codebases that:
- Use conditional compilation or function multiversioning
- Share large functions across SVE/SME variants
- Attempt to refactor or macro-wrap streaming annotations
The current behavior leads to confusing compiler errors and unnecessary refactoring.
Suggested Resolution
Unify the syntax rules for SME streaming attributes by:
- Allowing both attributes in both prefix and postfix positions, or
- Clearly documenting and enforcing consistent placement semantics
It looks like this issue is good for new comer. Please assign it to me.
The underlying reason for the inconsistency is that the __arm_locally_streaming is an attribute of the function definition, but __arm_streaming is an attribute of the function type. (You can apply __arm_streaming to a typedef.) The rest follows from standard C++ attribute parsing rules: whether the attribute applies to the type or the declaration depends on where it's placed.
We can maybe consider allowing __arm_streaming as a declaration attribute which modifies the type of the function.
This is all described in https://arm-software.github.io/acle/main/acle.html#keyword-attributes .