| ... | @@ -4876,14 +4876,30 @@ static LLVMValueRef ir_render_pop_count(CodeGen *g, IrExecutable *executable, Ir | ... | @@ -4876,14 +4876,30 @@ static LLVMValueRef ir_render_pop_count(CodeGen *g, IrExecutable *executable, Ir |
| 4876 | } | 4876 | } |
| 4877 | | 4877 | |
| 4878 | static LLVMValueRef ir_render_switch_br(CodeGen *g, IrExecutable *executable, IrInstructionSwitchBr *instruction) { | 4878 | static LLVMValueRef ir_render_switch_br(CodeGen *g, IrExecutable *executable, IrInstructionSwitchBr *instruction) { |
| 4879 | LLVMValueRef target_value = ir_llvm_value(g, instruction->target_value); | 4879 | ZigType *target_type = instruction->target_value->value->type; |
| 4880 | LLVMBasicBlockRef else_block = instruction->else_block->llvm_block; | 4880 | LLVMBasicBlockRef else_block = instruction->else_block->llvm_block; |
| | 4881 | |
| | 4882 | LLVMValueRef target_value = ir_llvm_value(g, instruction->target_value); |
| | 4883 | if (target_type->id == ZigTypeIdPointer) { |
| | 4884 | const ZigType *usize = g->builtin_types.entry_usize; |
| | 4885 | target_value = LLVMBuildPtrToInt(g->builder, target_value, usize->llvm_type, ""); |
| | 4886 | } |
| | 4887 | |
| 4881 | LLVMValueRef switch_instr = LLVMBuildSwitch(g->builder, target_value, else_block, | 4888 | LLVMValueRef switch_instr = LLVMBuildSwitch(g->builder, target_value, else_block, |
| 4882 | (unsigned)instruction->case_count); | 4889 | (unsigned)instruction->case_count); |
| | 4890 | |
| 4883 | for (size_t i = 0; i < instruction->case_count; i += 1) { | 4891 | for (size_t i = 0; i < instruction->case_count; i += 1) { |
| 4884 | IrInstructionSwitchBrCase *this_case = &instruction->cases[i]; | 4892 | IrInstructionSwitchBrCase *this_case = &instruction->cases[i]; |
| 4885 | LLVMAddCase(switch_instr, ir_llvm_value(g, this_case->value), this_case->block->llvm_block); | 4893 | |
| | 4894 | LLVMValueRef case_value = ir_llvm_value(g, this_case->value); |
| | 4895 | if (target_type->id == ZigTypeIdPointer) { |
| | 4896 | const ZigType *usize = g->builtin_types.entry_usize; |
| | 4897 | case_value = LLVMBuildPtrToInt(g->builder, case_value, usize->llvm_type, ""); |
| | 4898 | } |
| | 4899 | |
| | 4900 | LLVMAddCase(switch_instr, case_value, this_case->block->llvm_block); |
| 4886 | } | 4901 | } |
| | 4902 | |
| 4887 | return nullptr; | 4903 | return nullptr; |
| 4888 | } | 4904 | } |
| 4889 | | 4905 | |