Skip to content

Commit 8003563

Browse files
authored
Don't crash on variable sized gc allocations (#46914)
1 parent d97f248 commit 8003563

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
@@ -312,7 +312,10 @@ ssize_t Optimizer::getGCAllocSize(Instruction *I)
312312
if (call->getCalledOperand() != pass.alloc_obj_func)
313313
return -1;
314314
assert(call->arg_size() == 3);
315-
size_t sz = (size_t)cast<ConstantInt>(call->getArgOperand(1))->getZExtValue();
315+
auto CI = dyn_cast<ConstantInt>(call->getArgOperand(1));
316+
if (!CI)
317+
return -1;
318+
size_t sz = (size_t)CI->getZExtValue();
316319
if (sz < IntegerType::MAX_INT_BITS / 8 && sz < INT32_MAX)
317320
return sz;
318321
return -1;

0 commit comments

Comments
 (0)