Skip to content

Commit 9622ddf

Browse files
committed
[MC] Handle malformed target-feature
1 parent 9cc1585 commit 9622ddf

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

llvm/lib/MC/MCSubtargetInfo.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,11 @@ void ClearImpliedBits(FeatureBitset &Bits, unsigned Value,
5959

6060
static void ApplyFeatureFlag(FeatureBitset &Bits, StringRef Feature,
6161
ArrayRef<SubtargetFeatureKV> FeatureTable) {
62-
assert(SubtargetFeatures::hasFlag(Feature) &&
63-
"Feature flags should start with '+' or '-'");
64-
62+
if (!SubtargetFeatures::hasFlag(Feature)) {
63+
errs() << "feature flag '" << Feature
64+
<< "' must start with either '+' or '-' (ignoring feature)\n";
65+
return;
66+
}
6567
// Find feature in table.
6668
const SubtargetFeatureKV *FeatureEntry =
6769
Find(SubtargetFeatures::StripFlag(Feature), FeatureTable);
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
; Check that we handle a malformed feature flag gracefully.
2+
3+
; RUN: llc %s -o - 2>&1 | FileCheck %s
4+
5+
; CHECK: feature flag 'foobar' must start with either '+' or '-' (ignoring feature)
6+
define void @f() "target-features"="foobar" {
7+
entry:
8+
ret void
9+
}

0 commit comments

Comments
 (0)