From 2d4329e23c7b5fb3d5f5116c3cd8972b9c1a22ff Mon Sep 17 00:00:00 2001 From: David Mak Date: Fri, 7 Jun 2024 16:38:12 +0800 Subject: [PATCH] core/stmt: Use BB of last statement in if-else in phi --- nac3core/src/codegen/stmt.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/nac3core/src/codegen/stmt.rs b/nac3core/src/codegen/stmt.rs index 2fe22176..e5843ceb 100644 --- a/nac3core/src/codegen/stmt.rs +++ b/nac3core/src/codegen/stmt.rs @@ -872,12 +872,14 @@ pub fn gen_if_else_expr_callback<'ctx, 'a, G, CondFn, ThenFn, ElseFn, R>( ctx.builder.position_at_end(then_bb); let then_val = then_fn(generator, ctx)?; + let then_end_bb = ctx.builder.get_insert_block().unwrap(); if !ctx.is_terminated() { ctx.builder.build_unconditional_branch(end_bb).unwrap(); } ctx.builder.position_at_end(else_bb); let else_val = else_fn(generator, ctx)?; + let else_end_bb = ctx.builder.get_insert_block().unwrap(); if !ctx.is_terminated() { ctx.builder.build_unconditional_branch(end_bb).unwrap(); } @@ -889,7 +891,7 @@ pub fn gen_if_else_expr_callback<'ctx, 'a, G, CondFn, ThenFn, ElseFn, R>( assert_eq!(tv_ty, ev.as_basic_value_enum().get_type()); let phi = ctx.builder.build_phi(tv_ty, "").unwrap(); - phi.add_incoming(&[(&tv, then_bb), (&ev, else_bb)]); + phi.add_incoming(&[(&tv, then_end_bb), (&ev, else_end_bb)]); Some(phi.as_basic_value()) },