From 7e22a612808105a90ca5f66b0270a6aedff06af2 Mon Sep 17 00:00:00 2001 From: Stefan Weigl-Bosker Date: Fri, 19 Dec 2025 18:17:38 -0500 Subject: [PATCH] [MC] Handle malformed `target-feature` --- llvm/lib/MC/MCSubtargetInfo.cpp | 8 +++++--- llvm/test/CodeGen/Generic/invalid-target-feature.ll | 9 +++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 llvm/test/CodeGen/Generic/invalid-target-feature.ll diff --git a/llvm/lib/MC/MCSubtargetInfo.cpp b/llvm/lib/MC/MCSubtargetInfo.cpp index 89a08327dd259..242712a61f197 100644 --- a/llvm/lib/MC/MCSubtargetInfo.cpp +++ b/llvm/lib/MC/MCSubtargetInfo.cpp @@ -59,9 +59,11 @@ void ClearImpliedBits(FeatureBitset &Bits, unsigned Value, static void ApplyFeatureFlag(FeatureBitset &Bits, StringRef Feature, ArrayRef FeatureTable) { - assert(SubtargetFeatures::hasFlag(Feature) && - "Feature flags should start with '+' or '-'"); - + if (!SubtargetFeatures::hasFlag(Feature)) { + errs() << "Feature flag '" << Feature + << "' must start with either '+' or '-' (ignoring feature)\n"; + return; + } // Find feature in table. const SubtargetFeatureKV *FeatureEntry = Find(SubtargetFeatures::StripFlag(Feature), FeatureTable); diff --git a/llvm/test/CodeGen/Generic/invalid-target-feature.ll b/llvm/test/CodeGen/Generic/invalid-target-feature.ll new file mode 100644 index 0000000000000..43e16291576bd --- /dev/null +++ b/llvm/test/CodeGen/Generic/invalid-target-feature.ll @@ -0,0 +1,9 @@ +; Check that we handle a malformed feature flag gracefully. + +; RUN: llc %s -o - 2>&1 | FileCheck %s + +; CHECK: Feature flag 'foobar' must start with either '+' or '-' (ignoring feature) +define void @f() "target-features"="foobar" { +entry: + ret void +}