diff --git a/llvm/unittests/IR/IntrinsicsTest.cpp b/llvm/unittests/IR/IntrinsicsTest.cpp index 49af83609d98c..cfd99ed542162 100644 --- a/llvm/unittests/IR/IntrinsicsTest.cpp +++ b/llvm/unittests/IR/IntrinsicsTest.cpp @@ -189,4 +189,12 @@ TEST_F(IntrinsicsTest, InstrProfInheritance) { } } +// Check that getFnAttributes for intrinsics that do not have any function +// attributes correcty returns an empty set. +TEST(IntrinsicAttributes, TestGetFnAttributesBug) { + using namespace Intrinsic; + LLVMContext Context; + AttributeSet AS = getFnAttributes(Context, experimental_guard); + EXPECT_FALSE(AS.hasAttributes()); +} } // end namespace diff --git a/llvm/utils/TableGen/Basic/IntrinsicEmitter.cpp b/llvm/utils/TableGen/Basic/IntrinsicEmitter.cpp index 559868dd54efe..75dffb18fca5a 100644 --- a/llvm/utils/TableGen/Basic/IntrinsicEmitter.cpp +++ b/llvm/utils/TableGen/Basic/IntrinsicEmitter.cpp @@ -794,12 +794,15 @@ AttributeSet Intrinsic::getFnAttributes(LLVMContext &C, ID id) {{ if (id == 0) return AttributeSet(); auto [FnAttrID, _] = unpackID(IntrinsicsToAttributesMap[id - 1]); + if (FnAttrID == {}) + return AttributeSet(); return getIntrinsicFnAttributeSet(C, FnAttrID); } #endif // GET_INTRINSIC_ATTRIBUTES )", - UniqAttributesBitSize, MaxNumAttrs, NoFunctionAttrsID); + UniqAttributesBitSize, MaxNumAttrs, NoFunctionAttrsID, + NoFunctionAttrsID); } void IntrinsicEmitter::EmitIntrinsicToBuiltinMap(