llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: lrzlin
<details>
<summary>Changes</summary>
Add target features check in `CheckLoongArchBuiltinFunctionCall`, thus we could
through an error
when pass the `-mno-lsx` to clang while using the builtin LSX intrinsics for
global variables instead of
trigger an ICE.
Minimal Example:
```
// clang-20 --march=loongarch64 -mno-lsx -S -o - "x.cc"
__attribute__((__vector_size__(16))) long foo = __builtin_lsx_vinsgr2vr_w(foo,
0, 0);
```
and the compiler will output
```
x.cc:1:49: error: builtin requires at least one of the following extensions: lsx
1 | __attribute__((__vector_size__(16))) long foo =
__builtin_lsx_vinsgr2vr_w(foo, 0, 0);
|
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
```
Fix https://github.com/llvm/llvm-project/issues/131771
---
Full diff: https://github.com/llvm/llvm-project/pull/191811.diff
2 Files Affected:
- (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+4)
- (modified) clang/lib/Sema/SemaLoongArch.cpp (+18)
``````````diff
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index d4d09a8ecef36..d8970bbc6f60e 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -13502,6 +13502,10 @@ def err_riscv_attribute_interrupt_invalid_combination
: Error<
"RISC-V 'interrupt' attribute contains invalid combination of interrupt
types">;
def err_riscv_builtin_invalid_twiden : Error<"RISC-V XSfmm twiden must be 1, 2
or 4">;
+// LoongArch builtin required extension warning
+def err_loongarch_builtin_requires_extension : Error<
+ "builtin requires%select{| at least one of the following extensions}0: %1">;
+
def err_std_source_location_impl_not_found : Error<
"'std::source_location::__impl' was not found; it must be defined before
'__builtin_source_location' is called">;
def err_std_source_location_impl_malformed : Error<
diff --git a/clang/lib/Sema/SemaLoongArch.cpp b/clang/lib/Sema/SemaLoongArch.cpp
index c57a6f91a3dfc..b10f301bdc626 100644
--- a/clang/lib/Sema/SemaLoongArch.cpp
+++ b/clang/lib/Sema/SemaLoongArch.cpp
@@ -12,7 +12,9 @@
#include "clang/Sema/SemaLoongArch.h"
#include "clang/Basic/TargetBuiltins.h"
+#include "clang/Basic/TargetInfo.h"
#include "clang/Sema/Sema.h"
+#include "llvm/ADT/StringRef.h"
#include "llvm/Support/MathExtras.h"
namespace clang {
@@ -22,6 +24,22 @@ 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::StringMap<bool> FunctionFeatureMap;
+ Context.getFunctionFeatureMap(FunctionFeatureMap, FD);
+
+ llvm::StringRef Features =
Context.BuiltinInfo.getRequiredFeatures(BuiltinID);
+ if (!Features.empty()) {
+ llvm::SmallVector<StringRef> RequiredFeatures;
+ Features.split(RequiredFeatures, ',');
+ for (auto RF : RequiredFeatures)
+ if (!TI.hasFeature(RF) && !FunctionFeatureMap.lookup(RF))
+ return Diag(TheCall->getBeginLoc(),
+ diag::err_loongarch_builtin_requires_extension)
+ << /* IsExtension */ true << TheCall->getSourceRange() << RF;
+ }
+
switch (BuiltinID) {
default:
break;
``````````
</details>
https://github.com/llvm/llvm-project/pull/191811
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits