https://github.com/BeMg created https://github.com/llvm/llvm-project/pull/115991
Address https://github.com/llvm/llvm-project/issues/115000. This patch constrains the target_version feature to work only on RISC-V and AArch64 to prevent crashes in Clang. >From 28f7a2adc055ec6f30790e1e9535c71241a08e29 Mon Sep 17 00:00:00 2001 From: Piyou Chen <piyou.c...@sifive.com> Date: Tue, 12 Nov 2024 20:56:47 -0800 Subject: [PATCH] [TargetVersion] Only enable on RISC-V and AArch64 --- clang/include/clang/Basic/DiagnosticSemaKinds.td | 2 ++ clang/lib/Sema/SemaDeclAttr.cpp | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 509d45c0867590..6170c3c10b00ca 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -3282,6 +3282,8 @@ def warn_unsupported_target_attribute "attribute string; '%select{target|target_clones|target_version}3' " "attribute ignored">, InGroup<IgnoredAttributes>; +def err_target_version_unsupported + : Error<"target_version attribute is not supported in this target">; def err_attribute_unsupported : Error<"%0 attribute is not supported on targets missing %1;" " specify an appropriate -march= or -mcpu=">; diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index d05d326178e1b8..e2eaa00c666fc2 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -3040,6 +3040,11 @@ bool Sema::checkTargetVersionAttr(SourceLocation LiteralLoc, Decl *D, enum FirstParam { Unsupported }; enum SecondParam { None }; enum ThirdParam { Target, TargetClones, TargetVersion }; + + if (!Context.getTargetInfo().getTriple().isRISCV() && + !Context.getTargetInfo().getTriple().isAArch64()) + return Diag(LiteralLoc, diag::err_target_version_unsupported); + llvm::SmallVector<StringRef, 8> Features; if (Context.getTargetInfo().getTriple().isRISCV()) { llvm::SmallVector<StringRef, 8> AttrStrs; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits