[llvm] [LLVM] Fix a bug in `Intrinsic::getFnAttributes` (PR #161248)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 29 11:56:06 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-ir
Author: Rahul Joshi (jurahul)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/161248.diff
2 Files Affected:
- (modified) llvm/unittests/IR/IntrinsicsTest.cpp (+8)
- (modified) llvm/utils/TableGen/Basic/IntrinsicEmitter.cpp (+4-1)
``````````diff
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(
``````````
</details>
https://github.com/llvm/llvm-project/pull/161248
More information about the llvm-commits
mailing list