[llvm] 0d2b404 - [LLVM] Fix a bug in `Intrinsic::getFnAttributes` (#161248)

via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 30 05:29:39 PDT 2025


Author: Rahul Joshi
Date: 2025-09-30T05:29:34-07:00
New Revision: 0d2b404a352e1e1abe0c51e636755f1fc8352107

URL: https://github.com/llvm/llvm-project/commit/0d2b404a352e1e1abe0c51e636755f1fc8352107
DIFF: https://github.com/llvm/llvm-project/commit/0d2b404a352e1e1abe0c51e636755f1fc8352107.diff

LOG: [LLVM] Fix a bug in `Intrinsic::getFnAttributes` (#161248)

Added: 
    

Modified: 
    llvm/unittests/IR/IntrinsicsTest.cpp
    llvm/utils/TableGen/Basic/IntrinsicEmitter.cpp

Removed: 
    


################################################################################
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