[clang] [Clang][AArch64] Fix feature guards for SVE2p1 builtins available in SME{2}. (PR #147086)
Kerry McLaughlin via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 8 03:09:26 PDT 2025
================
@@ -569,34 +569,39 @@ static bool checkArmStreamingBuiltin(Sema &S, CallExpr *TheCall,
// * When compiling for SVE only, the caller must be in non-streaming mode.
// * When compiling for both SVE and SME, the caller can be in either mode.
if (BuiltinType == SemaARM::VerifyRuntimeMode) {
- llvm::StringMap<bool> CallerFeatureMapWithoutSVE;
- S.Context.getFunctionFeatureMap(CallerFeatureMapWithoutSVE, FD);
- CallerFeatureMapWithoutSVE["sve"] = false;
+ llvm::StringMap<bool> CallerFeatures;
+ S.Context.getFunctionFeatureMap(CallerFeatures, FD);
// Avoid emitting diagnostics for a function that can never compile.
- if (FnType == SemaARM::ArmStreaming && !CallerFeatureMapWithoutSVE["sme"])
+ if (FnType == SemaARM::ArmStreaming && !CallerFeatures["sme"])
return false;
- llvm::StringMap<bool> CallerFeatureMapWithoutSME;
- S.Context.getFunctionFeatureMap(CallerFeatureMapWithoutSME, FD);
- CallerFeatureMapWithoutSME["sme"] = false;
+ const auto FindTopLevelPipe = [](const char *S) {
+ unsigned Depth = 0;
+ unsigned I = 0, E = strlen(S);
+ for (; I < E; ++I) {
+ if (S[I] == '|' && Depth == 0)
+ break;
+ if (S[I] == '(')
+ ++Depth;
+ else if (S[I] == ')')
+ --Depth;
+ }
+ return I;
+ };
+
+ const char *RequiredFeatures =
+ S.Context.BuiltinInfo.getRequiredFeatures(BuiltinID);
+ unsigned PipeIdx = FindTopLevelPipe(RequiredFeatures);
+ assert(PipeIdx != 0 && PipeIdx != strlen(RequiredFeatures) &&
+ "Expected feature string of the form 'SVE-EXPR|SME-EXPR'");
+ StringRef NonStreamingBuiltinGuard = StringRef(RequiredFeatures, PipeIdx);
+ StringRef StreamingBuiltinGuard = StringRef(RequiredFeatures + PipeIdx + 1);
----------------
kmclaughlin-arm wrote:
My mistake, I was only considering the simpler cases such as `sve2p1|sme2` so I don't think regex is going to help here. I've approved the other patch which added these changes :)
https://github.com/llvm/llvm-project/pull/147086
More information about the cfe-commits
mailing list