Skip to content

Commit

Permalink
Don't crash on variable sized gc allocations (#46914)
Browse files Browse the repository at this point in the history
(cherry picked from commit 8003563)
  • Loading branch information
wsmoses authored and KristofferC committed Oct 28, 2022
1 parent 1b70b0f commit 1dcd60f
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/llvm-alloc-opt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,10 @@ ssize_t Optimizer::getGCAllocSize(Instruction *I)
if (call->getCalledOperand() != pass.alloc_obj_func)
return -1;
assert(call->arg_size() == 3);
size_t sz = (size_t)cast<ConstantInt>(call->getArgOperand(1))->getZExtValue();
auto CI = dyn_cast<ConstantInt>(call->getArgOperand(1));
if (!CI)
return -1;
size_t sz = (size_t)CI->getZExtValue();
if (sz < IntegerType::MAX_INT_BITS / 8 && sz < INT32_MAX)
return sz;
return -1;
Expand Down

0 comments on commit 1dcd60f

Please sign in to comment.