Skip to content

Commit 0d2b404

Browse files
authored
[LLVM] Fix a bug in Intrinsic::getFnAttributes (#161248)
1 parent 1553b3d commit 0d2b404

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

llvm/unittests/IR/IntrinsicsTest.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,4 +189,12 @@ TEST_F(IntrinsicsTest, InstrProfInheritance) {
189189
}
190190
}
191191

192+
// Check that getFnAttributes for intrinsics that do not have any function
193+
// attributes correcty returns an empty set.
194+
TEST(IntrinsicAttributes, TestGetFnAttributesBug) {
195+
using namespace Intrinsic;
196+
LLVMContext Context;
197+
AttributeSet AS = getFnAttributes(Context, experimental_guard);
198+
EXPECT_FALSE(AS.hasAttributes());
199+
}
192200
} // end namespace

llvm/utils/TableGen/Basic/IntrinsicEmitter.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -794,12 +794,15 @@ AttributeSet Intrinsic::getFnAttributes(LLVMContext &C, ID id) {{
794794
if (id == 0)
795795
return AttributeSet();
796796
auto [FnAttrID, _] = unpackID(IntrinsicsToAttributesMap[id - 1]);
797+
if (FnAttrID == {})
798+
return AttributeSet();
797799
return getIntrinsicFnAttributeSet(C, FnAttrID);
798800
}
799801
#endif // GET_INTRINSIC_ATTRIBUTES
800802
801803
)",
802-
UniqAttributesBitSize, MaxNumAttrs, NoFunctionAttrsID);
804+
UniqAttributesBitSize, MaxNumAttrs, NoFunctionAttrsID,
805+
NoFunctionAttrsID);
803806
}
804807

805808
void IntrinsicEmitter::EmitIntrinsicToBuiltinMap(

0 commit comments

Comments
 (0)