aboutsummaryrefslogtreecommitdiff
path: root/src/ir.cpp
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2019-05-14 18:25:14 -0400
committerAndrew Kelley <andrew@ziglang.org>2019-05-14 18:25:14 -0400
commitc08c222d5e8881631a4e3c56a9bda909c25e6c0b (patch)
tree772d599c4f7d9fd29671022f5b65acea8418248e /src/ir.cpp
parentdf4f77024e93dc3b60dd1d76d64e3c5ffa5ebd84 (diff)
downloadzig-c08c222d5e8881631a4e3c56a9bda909c25e6c0b.tar.gz
zig-c08c222d5e8881631a4e3c56a9bda909c25e6c0b.zip
fix regression on switch capture value for multiple cases
Diffstat (limited to 'src/ir.cpp')
-rw-r--r--src/ir.cpp17
1 files changed, 10 insertions, 7 deletions
diff --git a/src/ir.cpp b/src/ir.cpp
index 66dfc025b2..190230428c 100644
--- a/src/ir.cpp
+++ b/src/ir.cpp
@@ -6329,17 +6329,20 @@ static bool ir_gen_switch_prong_expr(IrBuilder *irb, Scope *scope, AstNode *swit
ZigVar *var = ir_create_var(irb, var_symbol_node, scope,
var_name, is_const, is_const, is_shadowable, var_is_comptime);
child_scope = var->child_scope;
- IrInstruction *var_ptr_value;
- if (prong_value != nullptr) {
- var_ptr_value = ir_build_switch_var(irb, scope, var_symbol_node, target_value_ptr, prong_value);
- } else {
+ IrInstruction *var_value;
+ if (out_switch_else_var != nullptr) {
IrInstructionSwitchElseVar *switch_else_var = ir_build_switch_else_var(irb, scope, var_symbol_node,
target_value_ptr);
*out_switch_else_var = switch_else_var;
- var_ptr_value = &switch_else_var->base;
+ IrInstruction *var_ptr_value = &switch_else_var->base;
+ var_value = var_is_ptr ? var_ptr_value : ir_build_load_ptr(irb, scope, var_symbol_node, var_ptr_value);
+ } else if (prong_value != nullptr) {
+ IrInstruction *var_ptr_value = ir_build_switch_var(irb, scope, var_symbol_node, target_value_ptr, prong_value);
+ var_value = var_is_ptr ? var_ptr_value : ir_build_load_ptr(irb, scope, var_symbol_node, var_ptr_value);
+ } else {
+ var_value = var_is_ptr ? target_value_ptr : ir_build_load_ptr(irb, scope, var_symbol_node,
+target_value_ptr);
}
- IrInstruction *var_value = var_is_ptr ?
- var_ptr_value : ir_build_load_ptr(irb, scope, var_symbol_node, var_ptr_value);
IrInstruction *var_type = nullptr; // infer the type
ir_build_var_decl_src(irb, scope, var_symbol_node, var, var_type, nullptr, var_value);
} else {