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 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 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")))