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 83a3ab6 commit de49fde
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 @@ -436,7 +436,10 @@ ssize_t Optimizer::getGCAllocSize(Instruction *I)
if (call->getCalledValue() != pass.alloc_obj)
return -1;
assert(call->getNumArgOperands() == 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 de49fde

Please sign in to comment.