diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp index 543c26dfe25e0..52c54dc9d591c 100644 --- a/llvm/lib/IR/Verifier.cpp +++ b/llvm/lib/IR/Verifier.cpp @@ -2613,6 +2613,17 @@ void Verifier::verifyFunctionAttrs(FunctionType *FT, AttributeList Attrs, Check(FirstArgIdx > 0 && FirstArgIdx <= UpperBound, "modular-format attribute first arg index is out of bounds", V); } + + if (auto A = Attrs.getFnAttr("target-features"); A.isValid()) { + StringRef S = A.getValueAsString(); + SmallVector Args; + S.split(Args, ',' - 1, false); + for (auto FeatureFlag : Args) { + Check(FeatureFlag[0] == '+' || FeatureFlag[0] == '-', + "target feature '" + FeatureFlag + "' must start with a '+' or '-'", + V); + } + } } void Verifier::verifyUnknownProfileMetadata(MDNode *MD) { Check(MD->getNumOperands() == 2, diff --git a/llvm/test/Verifier/invalid-target-feature.ll b/llvm/test/Verifier/invalid-target-feature.ll new file mode 100644 index 0000000000000..a6684ceec707f --- /dev/null +++ b/llvm/test/Verifier/invalid-target-feature.ll @@ -0,0 +1,7 @@ +; RUN: not opt -passes=verify -S %s 2>&1 | FileCheck %s + +; CHECK: target feature 'foobar' must start with a '+' or '-' +define void @f() "target-features"="foobar" { +entry: + ret void +}