Skip to content

Commit

Permalink
Don't crash on variable sized gc allocations
Browse files Browse the repository at this point in the history
  • Loading branch information
wsmoses committed Sep 26, 2022
1 parent d97f248 commit 6a1ba09
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 @@ -312,7 +312,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 6a1ba09

Please sign in to comment.