aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR/Attributes.cpp
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2021-07-12 20:54:58 +0200
committerNikita Popov <nikita.ppv@gmail.com>2021-07-12 21:11:59 +0200
commit3fb0621fafbb16ea157830b308c26a77ba0a04e3 (patch)
treec482caf782190ca4d6aebc45ebc77f9a84f9029b /llvm/lib/IR/Attributes.cpp
parentb4a6fa12d1fdcc9a446432218d9990a6c6797c83 (diff)
downloadllvm-3fb0621fafbb16ea157830b308c26a77ba0a04e3.zip
llvm-3fb0621fafbb16ea157830b308c26a77ba0a04e3.tar.gz
llvm-3fb0621fafbb16ea157830b308c26a77ba0a04e3.tar.bz2
[Attributes] Assert correct attribute constructor is used (NFCI)
Assert that enum/int/type attributes go through the constructor they are supposed to use. To make sure this can't happen via invalid bitcode, explicitly verify that the attribute kind if correct there.
Diffstat (limited to 'llvm/lib/IR/Attributes.cpp')
-rw-r--r--llvm/lib/IR/Attributes.cpp5
1 files changed, 5 insertions, 0 deletions
diff --git a/llvm/lib/IR/Attributes.cpp b/llvm/lib/IR/Attributes.cpp
index 45f7f18..3c3ffea 100644
--- a/llvm/lib/IR/Attributes.cpp
+++ b/llvm/lib/IR/Attributes.cpp
@@ -91,6 +91,11 @@ static std::pair<unsigned, unsigned> unpackVScaleRangeArgs(uint64_t Value) {
Attribute Attribute::get(LLVMContext &Context, Attribute::AttrKind Kind,
uint64_t Val) {
+ if (Val)
+ assert(Attribute::isIntAttrKind(Kind) && "Not an int attribute");
+ else
+ assert(Attribute::isEnumAttrKind(Kind) && "Not an enum attribute");
+
LLVMContextImpl *pImpl = Context.pImpl;
FoldingSetNodeID ID;
ID.AddInteger(Kind);