diff options
author | Nikita Popov <npopov@redhat.com> | 2025-04-17 11:11:00 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-04-17 11:11:00 +0200 |
commit | c3c0b27f2d34cd106df278afc378c30fe493f513 (patch) | |
tree | 2e7c6d6b74f588fb706b2f72b0965c90873ce25f /llvm/lib/IR/Function.cpp | |
parent | bd49bbaaafc98433a2cb4e95ce25b7a201baf5a5 (diff) | |
download | llvm-c3c0b27f2d34cd106df278afc378c30fe493f513.zip llvm-c3c0b27f2d34cd106df278afc378c30fe493f513.tar.gz llvm-c3c0b27f2d34cd106df278afc378c30fe493f513.tar.bz2 |
[Intrinsics] Add support for range attributes (#135642)
Add support for specifying range attributes in Intrinsics.td. Use this
to specify the ucmp/scmp range [-1,2).
This case is trickier than existing intrinsic attributes, because we
need to create the attribute with the correct bitwidth. As such, the
attribute construction now needs to be aware of the function type.
We also need to be careful to no longer assign attributes on intrinsics
with invalid signatures, as we'd make invalid assumptions about the
number of arguments etc otherwise.
Fixes https://github.com/llvm/llvm-project/issues/130179.
Diffstat (limited to 'llvm/lib/IR/Function.cpp')
-rw-r--r-- | llvm/lib/IR/Function.cpp | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/llvm/lib/IR/Function.cpp b/llvm/lib/IR/Function.cpp index 3644fab..ce0f710 100644 --- a/llvm/lib/IR/Function.cpp +++ b/llvm/lib/IR/Function.cpp @@ -514,8 +514,15 @@ Function::Function(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, // Ensure intrinsics have the right parameter attributes. // Note, the IntID field will have been set in Value::setName if this function // name is a valid intrinsic ID. - if (IntID) - setAttributes(Intrinsic::getAttributes(getContext(), IntID)); + if (IntID) { + // Don't set the attributes if the intrinsic signature is invalid. This + // case will either be auto-upgraded or fail verification. + SmallVector<Type *> OverloadTys; + if (!Intrinsic::getIntrinsicSignature(IntID, Ty, OverloadTys)) + return; + + setAttributes(Intrinsic::getAttributes(getContext(), IntID, Ty)); + } } Function::~Function() { |