| ... | ... | @@ -5224,6 +5224,15 @@ static LLVMValueRef ir_render_cmpxchg(CodeGen *g, IrExecutableGen *executable, I |
| 5224 | 5224 | LLVMValueRef cmp_val = ir_llvm_value(g, instruction->cmp_value); |
| 5225 | 5225 | LLVMValueRef new_val = ir_llvm_value(g, instruction->new_value); |
| 5226 | 5226 | |
| 5227 | ZigType *operand_type = instruction->new_value->value->type; |
| 5228 | if (operand_type->id == ZigTypeIdBool) { |
| 5229 | // treat bool as u8 |
| 5230 | ptr_val = LLVMBuildBitCast(g->builder, ptr_val, |
| 5231 | LLVMPointerType(g->builtin_types.entry_u8->llvm_type, 0), ""); |
| 5232 | cmp_val = LLVMConstZExt(cmp_val, g->builtin_types.entry_u8->llvm_type); |
| 5233 | new_val = LLVMConstZExt(new_val, g->builtin_types.entry_u8->llvm_type); |
| 5234 | } |
| 5235 | |
| 5227 | 5236 | LLVMAtomicOrdering success_order = to_LLVMAtomicOrdering(instruction->success_order); |
| 5228 | 5237 | LLVMAtomicOrdering failure_order = to_LLVMAtomicOrdering(instruction->failure_order); |
| 5229 | 5238 | |
| ... | ... | @@ -5236,6 +5245,9 @@ static LLVMValueRef ir_render_cmpxchg(CodeGen *g, IrExecutableGen *executable, I |
| 5236 | 5245 | |
| 5237 | 5246 | if (!handle_is_ptr(g, optional_type)) { |
| 5238 | 5247 | LLVMValueRef payload_val = LLVMBuildExtractValue(g->builder, result_val, 0, ""); |
| 5248 | if (operand_type->id == ZigTypeIdBool) { |
| 5249 | payload_val = LLVMBuildTrunc(g->builder, payload_val, g->builtin_types.entry_bool->llvm_type, ""); |
| 5250 | } |
| 5239 | 5251 | LLVMValueRef success_bit = LLVMBuildExtractValue(g->builder, result_val, 1, ""); |
| 5240 | 5252 | return LLVMBuildSelect(g->builder, success_bit, LLVMConstNull(get_llvm_type(g, child_type)), payload_val, ""); |
| 5241 | 5253 | } |
| ... | ... | @@ -5250,6 +5262,9 @@ static LLVMValueRef ir_render_cmpxchg(CodeGen *g, IrExecutableGen *executable, I |
| 5250 | 5262 | ir_assert(type_has_bits(g, child_type), &instruction->base); |
| 5251 | 5263 | |
| 5252 | 5264 | LLVMValueRef payload_val = LLVMBuildExtractValue(g->builder, result_val, 0, ""); |
| 5265 | if (operand_type->id == ZigTypeIdBool) { |
| 5266 | payload_val = LLVMBuildTrunc(g->builder, payload_val, g->builtin_types.entry_bool->llvm_type, ""); |
| 5267 | } |
| 5253 | 5268 | LLVMValueRef val_ptr = LLVMBuildStructGEP(g->builder, result_loc, maybe_child_index, ""); |
| 5254 | 5269 | gen_assign_raw(g, val_ptr, get_pointer_to_type(g, child_type, false), payload_val); |
| 5255 | 5270 | |
| ... | ... | @@ -5827,6 +5842,16 @@ static LLVMValueRef ir_render_atomic_rmw(CodeGen *g, IrExecutableGen *executable |
| 5827 | 5842 | LLVMValueRef ptr = ir_llvm_value(g, instruction->ptr); |
| 5828 | 5843 | LLVMValueRef operand = ir_llvm_value(g, instruction->operand); |
| 5829 | 5844 | |
| 5845 | if (operand_type->id == ZigTypeIdBool) { |
| 5846 | // treat bool as u8 |
| 5847 | LLVMValueRef casted_ptr = LLVMBuildBitCast(g->builder, ptr, |
| 5848 | LLVMPointerType(g->builtin_types.entry_u8->llvm_type, 0), ""); |
| 5849 | LLVMValueRef casted_operand = LLVMBuildPtrToInt(g->builder, operand, g->builtin_types.entry_u8->llvm_type, ""); |
| 5850 | LLVMValueRef uncasted_result = ZigLLVMBuildAtomicRMW(g->builder, op, casted_ptr, casted_operand, ordering, |
| 5851 | g->is_single_threaded); |
| 5852 | return LLVMBuildTrunc(g->builder, uncasted_result, g->builtin_types.entry_bool->llvm_type, ""); |
| 5853 | } |
| 5854 | |
| 5830 | 5855 | if (get_codegen_ptr_type_bail(g, operand_type) == nullptr) { |
| 5831 | 5856 | return ZigLLVMBuildAtomicRMW(g->builder, op, ptr, operand, ordering, g->is_single_threaded); |
| 5832 | 5857 | } |
| ... | ... | @@ -5845,6 +5870,16 @@ static LLVMValueRef ir_render_atomic_load(CodeGen *g, IrExecutableGen *executabl |
| 5845 | 5870 | { |
| 5846 | 5871 | LLVMAtomicOrdering ordering = to_LLVMAtomicOrdering(instruction->ordering); |
| 5847 | 5872 | LLVMValueRef ptr = ir_llvm_value(g, instruction->ptr); |
| 5873 | |
| 5874 | ZigType *operand_type = instruction->ptr->value->type->data.pointer.child_type; |
| 5875 | if (operand_type->id == ZigTypeIdBool) { |
| 5876 | // treat bool as u8 |
| 5877 | ptr = LLVMBuildBitCast(g->builder, ptr, |
| 5878 | LLVMPointerType(g->builtin_types.entry_u8->llvm_type, 0), ""); |
| 5879 | LLVMValueRef load_inst = gen_load(g, ptr, instruction->ptr->value->type, ""); |
| 5880 | LLVMSetOrdering(load_inst, ordering); |
| 5881 | return LLVMBuildTrunc(g->builder, load_inst, g->builtin_types.entry_bool->llvm_type, ""); |
| 5882 | } |
| 5848 | 5883 | LLVMValueRef load_inst = gen_load(g, ptr, instruction->ptr->value->type, ""); |
| 5849 | 5884 | LLVMSetOrdering(load_inst, ordering); |
| 5850 | 5885 | return load_inst; |
| ... | ... | @@ -5856,6 +5891,14 @@ static LLVMValueRef ir_render_atomic_store(CodeGen *g, IrExecutableGen *executab |
| 5856 | 5891 | LLVMAtomicOrdering ordering = to_LLVMAtomicOrdering(instruction->ordering); |
| 5857 | 5892 | LLVMValueRef ptr = ir_llvm_value(g, instruction->ptr); |
| 5858 | 5893 | LLVMValueRef value = ir_llvm_value(g, instruction->value); |
| 5894 | |
| 5895 | ZigType *operand_type = instruction->value->value->type; |
| 5896 | if (operand_type->id == ZigTypeIdBool) { |
| 5897 | // treat bool as u8 |
| 5898 | ptr = LLVMBuildBitCast(g->builder, ptr, |
| 5899 | LLVMPointerType(g->builtin_types.entry_u8->llvm_type, 0), ""); |
| 5900 | value = LLVMConstZExt(value, g->builtin_types.entry_u8->llvm_type); |
| 5901 | } |
| 5859 | 5902 | LLVMValueRef store_inst = gen_store(g, value, ptr, instruction->ptr->value->type); |
| 5860 | 5903 | LLVMSetOrdering(store_inst, ordering); |
| 5861 | 5904 | return nullptr; |