Skip to content

Commit de49fde

Browse files
committed
Don't crash on variable sized gc allocations
1 parent 83a3ab6 commit de49fde

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/llvm-alloc-opt.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,10 @@ ssize_t Optimizer::getGCAllocSize(Instruction *I)
436436
if (call->getCalledValue() != pass.alloc_obj)
437437
return -1;
438438
assert(call->getNumArgOperands() == 3);
439-
size_t sz = (size_t)cast<ConstantInt>(call->getArgOperand(1))->getZExtValue();
439+
auto CI = dyn_cast<ConstantInt>(call->getArgOperand(1));
440+
if (!CI)
441+
return -1;
442+
size_t sz = (size_t)CI->getZExtValue();
440443
if (sz < IntegerType::MAX_INT_BITS / 8 && sz < INT32_MAX)
441444
return sz;
442445
return -1;

0 commit comments

Comments
 (0)