https://github.com/ecnelises created 
https://github.com/llvm/llvm-project/pull/172844

Fixes #172653 

>From 2a5fbef87744c65f3bac7fb98eacf1f0ab7eb303 Mon Sep 17 00:00:00 2001
From: Qiu Chaofan <[email protected]>
Date: Thu, 18 Dec 2025 16:01:58 +0800
Subject: [PATCH] [X86] Ignore invalid features in FMV priority

---
 clang/lib/Basic/Targets/X86.cpp      | 4 +++-
 clang/test/Sema/attr-target-clones.c | 3 +++
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Basic/Targets/X86.cpp b/clang/lib/Basic/Targets/X86.cpp
index f00d435937b92..a226679865775 100644
--- a/clang/lib/Basic/Targets/X86.cpp
+++ b/clang/lib/Basic/Targets/X86.cpp
@@ -1320,7 +1320,7 @@ static llvm::X86::ProcessorFeatures getFeature(StringRef 
Name) {
 }
 
 llvm::APInt X86TargetInfo::getFMVPriority(ArrayRef<StringRef> Features) const {
-  auto getPriority = [](StringRef Feature) -> unsigned {
+  auto getPriority = [this](StringRef Feature) -> unsigned {
     // Valid CPUs have a 'key feature' that compares just better than its key
     // feature.
     using namespace llvm::X86;
@@ -1331,6 +1331,8 @@ llvm::APInt 
X86TargetInfo::getFMVPriority(ArrayRef<StringRef> Features) const {
     }
     // Now we know we have a feature, so get its priority and shift it a few so
     // that we have sufficient room for the CPUs (above).
+    if (!validateCpuSupports(Feature))
+      return 0;
     return getFeaturePriority(getFeature(Feature)) << 1;
   };
 
diff --git a/clang/test/Sema/attr-target-clones.c 
b/clang/test/Sema/attr-target-clones.c
index 40688772eeb96..38d727fed039a 100644
--- a/clang/test/Sema/attr-target-clones.c
+++ b/clang/test/Sema/attr-target-clones.c
@@ -4,6 +4,9 @@
 void __attribute__((target_clones("sse4.2", "arch=sandybridge")))
 no_default(void);
 
+// expected-warning@+1 {{unsupported 'sse4' in the 'target_clones' attribute 
string; 'target_clones' attribute ignored}}
+void __attribute__((target_clones("sse4"))) invalid_target(void);
+
 // expected-error@+2 {{'target_clones' and 'target' attributes are not 
compatible}}
 // expected-note@+1 {{conflicting attribute is here}}
 void __attribute__((target("sse4.2"), target_clones("arch=sandybridge")))

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to