Skip to content

Commit ce06aa6

Browse files
wsmosesKristofferC
authored andcommitted
Don't crash on variable sized gc allocations (#46914)
(cherry picked from commit 8003563)
1 parent 187177d commit ce06aa6

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
@@ -425,7 +425,10 @@ ssize_t Optimizer::getGCAllocSize(Instruction *I)
425425
if (call->getCalledOperand() != pass.alloc_obj_func)
426426
return -1;
427427
assert(call->getNumArgOperands() == 3);
428-
size_t sz = (size_t)cast<ConstantInt>(call->getArgOperand(1))->getZExtValue();
428+
auto CI = dyn_cast<ConstantInt>(call->getArgOperand(1));
429+
if (!CI)
430+
return -1;
431+
size_t sz = (size_t)CI->getZExtValue();
429432
if (sz < IntegerType::MAX_INT_BITS / 8 && sz < INT32_MAX)
430433
return sz;
431434
return -1;

0 commit comments

Comments
 (0)