[llvm] [LLVM] Fix a bug in `Intrinsic::getFnAttributes` (PR #161248)
Rahul Joshi via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 29 11:00:39 PDT 2025
https://github.com/jurahul created https://github.com/llvm/llvm-project/pull/161248
When an intrinsic has no function attributes, the current code will hit an assert in `getIntrinsicFnAttributeSet`. Fix this by checking for the sentinel `NoFunctionAttrsID` value and returning an empty attribute set.
>From e8d3c388acd477199f8be4c39828abc362b438f9 Mon Sep 17 00:00:00 2001
From: Rahul Joshi <rjoshi at nvidia.com>
Date: Mon, 29 Sep 2025 10:56:37 -0700
Subject: [PATCH] [LLVM] Fix a bug in `Intrinsic::getFnAttributes`
When an intrinsic has no function attributes, the current code will
hit an assert in `getIntrinsicFnAttributeSet`. Fix this by checking
for the sentinel `NoFunctionAttrsID` value and returning an empty
attribute set.
---
llvm/unittests/IR/IntrinsicsTest.cpp | 8 ++++++++
llvm/utils/TableGen/Basic/IntrinsicEmitter.cpp | 5 ++++-
2 files changed, 12 insertions(+), 1 deletion(-)
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(
More information about the llvm-commits
mailing list