From 6a1ba090901cd15378acec12c4f172fb7d4c9e6b Mon Sep 17 00:00:00 2001 From: "William S. Moses" Date: Mon, 26 Sep 2022 14:57:34 -0400 Subject: [PATCH] Don't crash on variable sized gc allocations --- src/llvm-alloc-opt.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/llvm-alloc-opt.cpp b/src/llvm-alloc-opt.cpp index 5e44249e7b9c0..9cc125820d2f3 100644 --- a/src/llvm-alloc-opt.cpp +++ b/src/llvm-alloc-opt.cpp @@ -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(call->getArgOperand(1))->getZExtValue(); + auto CI = dyn_cast(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;