[clang] [NFC][Clang][FMV] Refactor sema checking of target_version/clones attributes. (PR #149067)
Alexandros Lamprineas via cfe-commits
cfe-commits at lists.llvm.org
Wed Jul 16 07:27:07 PDT 2025
================
@@ -1056,4 +1056,62 @@ void SemaX86::handleForceAlignArgPointerAttr(Decl *D, const ParsedAttr &AL) {
X86ForceAlignArgPointerAttr(getASTContext(), AL));
}
+enum FirstParam { Unsupported, Duplicate, Unknown };
+enum SecondParam { None, CPU, Tune };
+enum ThirdParam { Target, TargetClones, TargetVersion };
+
+bool SemaX86::checkTargetClonesAttr(SmallVectorImpl<StringRef> &Strs,
+ SmallVectorImpl<SourceLocation> &Locs,
+ SmallVectorImpl<SmallString<64>> &Buffer) {
+ assert(Strs.size() == Locs.size() &&
+ "Mismatch between number of strings and locations");
+
+ bool HasDefault = false;
+ bool HasComma = false;
+ for (unsigned I = 0; I < Strs.size(); ++I) {
+ StringRef Str = Strs[I].trim();
+ SourceLocation Loc = Locs[I];
+
+ if (Str.empty() || Str.ends_with(','))
+ return Diag(Loc, diag::warn_unsupported_target_attribute)
+ << Unsupported << None << "" << TargetClones;
+
+ if (Str.contains(','))
+ HasComma = true;
+
+ StringRef LHS;
+ StringRef RHS = Str;
+ do {
+ std::tie(LHS, RHS) = RHS.split(',');
+ LHS = LHS.trim();
+ SourceLocation CurLoc = Loc.getLocWithOffset(LHS.data() - Str.data());
+
+ if (LHS.starts_with("arch=")) {
+ if (!getASTContext().getTargetInfo().isValidCPUName(
+ LHS.drop_front(sizeof("arch=") - 1)))
+ return Diag(CurLoc, diag::warn_unsupported_target_attribute)
+ << Unsupported << CPU << LHS.drop_front(sizeof("arch=") - 1)
+ << TargetClones;
+ } else if (LHS == "default")
+ HasDefault = true;
+ else if (!getASTContext().getTargetInfo().isValidFeatureName(LHS) ||
+ getASTContext().getTargetInfo().getFMVPriority(LHS) == 0)
+ return Diag(CurLoc, diag::warn_unsupported_target_attribute)
+ << Unsupported << None << LHS << TargetClones;
+
+ if (llvm::is_contained(Buffer, LHS))
----------------
labrinea wrote:
There is a test in place for this https://github.com/llvm/llvm-project/blob/main/clang/test/Sema/attr-target-clones.c#L70
https://github.com/llvm/llvm-project/pull/149067
More information about the cfe-commits
mailing list