From d6a1cecb9d338c34c1b3ac4e60b0ee4055e367ce Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Fri, 17 Feb 2023 13:45:16 +0100 Subject: [PATCH] Fix of LLVM codegen for optionals. --- src/compiler/llvm_codegen_stmt.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/compiler/llvm_codegen_stmt.c b/src/compiler/llvm_codegen_stmt.c index 89b01a469..28daab15f 100644 --- a/src/compiler/llvm_codegen_stmt.c +++ b/src/compiler/llvm_codegen_stmt.c @@ -1261,11 +1261,13 @@ static void llvm_prune_optional(GenContext *c, LLVMBasicBlockRef discard_fail) // Optionally remove the comparison if (!LLVMGetFirstUse(compared)) { + LLVMValueRef operand = NULL; if (LLVMGetInstructionOpcode(compared) == LLVMCall) { - LLVMInstructionEraseFromParent(LLVMGetOperand(compared, 0)); + operand = LLVMGetOperand(compared, 0); } LLVMInstructionEraseFromParent(compared); + if (operand) LLVMInstructionEraseFromParent(operand); } // Update the context c->current_block = prev_block;