[clang] [clang][LoongArch] Check target features in CheckLoongArchBuiltinFunctionCall (PR #191811)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 16 04:14:23 PDT 2026
================
@@ -22,6 +25,20 @@ SemaLoongArch::SemaLoongArch(Sema &S) : SemaBase(S) {}
bool SemaLoongArch::CheckLoongArchBuiltinFunctionCall(const TargetInfo &TI,
unsigned BuiltinID,
CallExpr *TheCall) {
+ ASTContext &Context = getASTContext();
+ const FunctionDecl *FD = SemaRef.getCurFunctionDecl();
+
+ llvm::StringRef Features = Context.BuiltinInfo.getRequiredFeatures(BuiltinID);
+ // Only check it when the builtin is not used in a function.
+ if (!Features.empty() && !FD) {
+ llvm::SmallVector<StringRef> RequiredFeatures;
+ Features.split(RequiredFeatures, ',');
+ for (auto RF : RequiredFeatures)
+ if (!TI.hasFeature(RF))
----------------
wangleiat wrote:
`TargetInfo::hasFeature()` is backend-dependent and may not reliably cover all builtin feature checks. Consider using `Builtin::evaluateRequiredTargetFeatures()` as the common path to ensure consistent feature evaluation.
```
typedef long long __m128i __attribute__ ((__vector_size__ (16), __may_alias__));
__m128i foo = __builtin_lsx_vfrsqrte_s(foo);
```
https://github.com/llvm/llvm-project/pull/191811
More information about the cfe-commits
mailing list