diff options
author | Florian Hahn <flo@fhahn.com> | 2018-12-12 02:22:12 +0000 |
---|---|---|
committer | Florian Hahn <flo@fhahn.com> | 2018-12-12 02:22:12 +0000 |
commit | cc419ad7df2b90d07b7e36244cc24269be9435d8 (patch) | |
tree | 8a525845a798610e20dbd9ee1f5399e86d36da1d /llvm/lib/IR/Constants.cpp | |
parent | 8272a71285609b9786bfc83611737069063b5414 (diff) | |
download | llvm-cc419ad7df2b90d07b7e36244cc24269be9435d8.zip llvm-cc419ad7df2b90d07b7e36244cc24269be9435d8.tar.gz llvm-cc419ad7df2b90d07b7e36244cc24269be9435d8.tar.bz2 |
[ConstantInt] Check active bits before calling getZExtValue.
Without this check, we hit an assertion in getZExtValue, if the constant
value does not fit into an uint64_t.
As getZExtValue returns an uint64_t, should we update
getAggregateElement to take an uin64_t as well?
This fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=6109.
Reviewers: efriedma, craig.topper, spatel
Reviewed By: efriedma
Differential Revision: https://reviews.llvm.org/D55547
llvm-svn: 348906
Diffstat (limited to 'llvm/lib/IR/Constants.cpp')
-rw-r--r-- | llvm/lib/IR/Constants.cpp | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/llvm/lib/IR/Constants.cpp b/llvm/lib/IR/Constants.cpp index 22ffc811..df09d13 100644 --- a/llvm/lib/IR/Constants.cpp +++ b/llvm/lib/IR/Constants.cpp @@ -350,8 +350,12 @@ Constant *Constant::getAggregateElement(unsigned Elt) const { Constant *Constant::getAggregateElement(Constant *Elt) const { assert(isa<IntegerType>(Elt->getType()) && "Index must be an integer"); - if (ConstantInt *CI = dyn_cast<ConstantInt>(Elt)) + if (ConstantInt *CI = dyn_cast<ConstantInt>(Elt)) { + // Check if the constant fits into an uint64_t. + if (CI->getValue().getActiveBits() > 64) + return nullptr; return getAggregateElement(CI->getZExtValue()); + } return nullptr; } |