| ... | ... | @@ -227,7 +227,7 @@ static IrInstGen *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name |
| 227 | 227 | static void ir_assert(bool ok, IrInst* source_instruction); |
| 228 | 228 | static void ir_assert_gen(bool ok, IrInstGen *source_instruction); |
| 229 | 229 | static IrInstGen *ir_get_var_ptr(IrAnalyze *ira, IrInst *source_instr, ZigVar *var); |
| 230 | | static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstGen *op); |
| 230 | static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstGen *op, ZigType **actual_type); |
| 231 | 231 | static IrInstSrc *ir_lval_wrap(IrBuilderSrc *irb, Scope *scope, IrInstSrc *value, LVal lval, ResultLoc *result_loc); |
| 232 | 232 | static IrInstSrc *ir_expr_wrap(IrBuilderSrc *irb, Scope *scope, IrInstSrc *inst, ResultLoc *result_loc); |
| 233 | 233 | static ZigType *adjust_ptr_align(CodeGen *g, ZigType *ptr_type, uint32_t new_align); |
| ... | ... | @@ -3406,7 +3406,7 @@ static IrInstSrc *ir_build_cmpxchg_src(IrBuilderSrc *irb, Scope *scope, AstNode |
| 3406 | 3406 | |
| 3407 | 3407 | static IrInstGen *ir_build_cmpxchg_gen(IrAnalyze *ira, IrInst *source_instruction, ZigType *result_type, |
| 3408 | 3408 | IrInstGen *ptr, IrInstGen *cmp_value, IrInstGen *new_value, |
| 3409 | | AtomicOrder success_order, AtomicOrder failure_order, bool is_weak, IrInstGen *result_loc) |
| 3409 | AtomicOrder success_order, AtomicOrder failure_order, bool is_weak, IrInstGen *result_loc, ZigType *actual_type) |
| 3410 | 3410 | { |
| 3411 | 3411 | IrInstGenCmpxchg *instruction = ir_build_inst_gen<IrInstGenCmpxchg>(&ira->new_irb, |
| 3412 | 3412 | source_instruction->scope, source_instruction->source_node); |
| ... | ... | @@ -3418,6 +3418,7 @@ static IrInstGen *ir_build_cmpxchg_gen(IrAnalyze *ira, IrInst *source_instructio |
| 3418 | 3418 | instruction->failure_order = failure_order; |
| 3419 | 3419 | instruction->is_weak = is_weak; |
| 3420 | 3420 | instruction->result_loc = result_loc; |
| 3421 | instruction->actual_type = actual_type; |
| 3421 | 3422 | |
| 3422 | 3423 | ir_ref_inst_gen(ptr, ira->new_irb.current_basic_block); |
| 3423 | 3424 | ir_ref_inst_gen(cmp_value, ira->new_irb.current_basic_block); |
| ... | ... | @@ -4554,7 +4555,7 @@ static IrInstSrc *ir_build_atomic_rmw_src(IrBuilderSrc *irb, Scope *scope, AstNo |
| 4554 | 4555 | } |
| 4555 | 4556 | |
| 4556 | 4557 | static IrInstGen *ir_build_atomic_rmw_gen(IrAnalyze *ira, IrInst *source_instr, |
| 4557 | | IrInstGen *ptr, IrInstGen *operand, AtomicRmwOp op, AtomicOrder ordering, ZigType *operand_type) |
| 4558 | IrInstGen *ptr, IrInstGen *operand, AtomicRmwOp op, AtomicOrder ordering, ZigType *operand_type, ZigType *actual_type) |
| 4558 | 4559 | { |
| 4559 | 4560 | IrInstGenAtomicRmw *instruction = ir_build_inst_gen<IrInstGenAtomicRmw>(&ira->new_irb, source_instr->scope, source_instr->source_node); |
| 4560 | 4561 | instruction->base.value->type = operand_type; |
| ... | ... | @@ -4562,6 +4563,7 @@ static IrInstGen *ir_build_atomic_rmw_gen(IrAnalyze *ira, IrInst *source_instr, |
| 4562 | 4563 | instruction->op = op; |
| 4563 | 4564 | instruction->operand = operand; |
| 4564 | 4565 | instruction->ordering = ordering; |
| 4566 | instruction->actual_type = actual_type; |
| 4565 | 4567 | |
| 4566 | 4568 | ir_ref_inst_gen(ptr, ira->new_irb.current_basic_block); |
| 4567 | 4569 | ir_ref_inst_gen(operand, ira->new_irb.current_basic_block); |
| ... | ... | @@ -4585,13 +4587,14 @@ static IrInstSrc *ir_build_atomic_load_src(IrBuilderSrc *irb, Scope *scope, AstN |
| 4585 | 4587 | } |
| 4586 | 4588 | |
| 4587 | 4589 | static IrInstGen *ir_build_atomic_load_gen(IrAnalyze *ira, IrInst *source_instr, |
| 4588 | | IrInstGen *ptr, AtomicOrder ordering, ZigType *operand_type) |
| 4590 | IrInstGen *ptr, AtomicOrder ordering, ZigType *operand_type, ZigType *actual_type) |
| 4589 | 4591 | { |
| 4590 | 4592 | IrInstGenAtomicLoad *instruction = ir_build_inst_gen<IrInstGenAtomicLoad>(&ira->new_irb, |
| 4591 | 4593 | source_instr->scope, source_instr->source_node); |
| 4592 | 4594 | instruction->base.value->type = operand_type; |
| 4593 | 4595 | instruction->ptr = ptr; |
| 4594 | 4596 | instruction->ordering = ordering; |
| 4597 | instruction->actual_type = actual_type; |
| 4595 | 4598 | |
| 4596 | 4599 | ir_ref_inst_gen(ptr, ira->new_irb.current_basic_block); |
| 4597 | 4600 | |
| ... | ... | @@ -4616,13 +4619,14 @@ static IrInstSrc *ir_build_atomic_store_src(IrBuilderSrc *irb, Scope *scope, Ast |
| 4616 | 4619 | } |
| 4617 | 4620 | |
| 4618 | 4621 | static IrInstGen *ir_build_atomic_store_gen(IrAnalyze *ira, IrInst *source_instr, |
| 4619 | | IrInstGen *ptr, IrInstGen *value, AtomicOrder ordering) |
| 4622 | IrInstGen *ptr, IrInstGen *value, AtomicOrder ordering, ZigType *actual_type) |
| 4620 | 4623 | { |
| 4621 | 4624 | IrInstGenAtomicStore *instruction = ir_build_inst_void<IrInstGenAtomicStore>(&ira->new_irb, |
| 4622 | 4625 | source_instr->scope, source_instr->source_node); |
| 4623 | 4626 | instruction->ptr = ptr; |
| 4624 | 4627 | instruction->value = value; |
| 4625 | 4628 | instruction->ordering = ordering; |
| 4629 | instruction->actual_type = actual_type; |
| 4626 | 4630 | |
| 4627 | 4631 | ir_ref_inst_gen(ptr, ira->new_irb.current_basic_block); |
| 4628 | 4632 | ir_ref_inst_gen(value, ira->new_irb.current_basic_block); |
| ... | ... | @@ -25121,7 +25125,8 @@ static IrInstGen *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstSrcEmb |
| 25121 | 25125 | } |
| 25122 | 25126 | |
| 25123 | 25127 | static IrInstGen *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstSrcCmpxchg *instruction) { |
| 25124 | | ZigType *operand_type = ir_resolve_atomic_operand_type(ira, instruction->type_value->child); |
| 25128 | ZigType *actual_type; |
| 25129 | ZigType *operand_type = ir_resolve_atomic_operand_type(ira, instruction->type_value->child, &actual_type); |
| 25125 | 25130 | if (type_is_invalid(operand_type)) |
| 25126 | 25131 | return ira->codegen->invalid_inst_gen; |
| 25127 | 25132 | |
| ... | ... | @@ -25213,7 +25218,7 @@ static IrInstGen *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstSrcCmpxch |
| 25213 | 25218 | |
| 25214 | 25219 | return ir_build_cmpxchg_gen(ira, &instruction->base.base, result_type, |
| 25215 | 25220 | casted_ptr, casted_cmp_value, casted_new_value, |
| 25216 | | success_order, failure_order, instruction->is_weak, result_loc); |
| 25221 | success_order, failure_order, instruction->is_weak, result_loc, actual_type); |
| 25217 | 25222 | } |
| 25218 | 25223 | |
| 25219 | 25224 | static IrInstGen *ir_analyze_instruction_fence(IrAnalyze *ira, IrInstSrcFence *instruction) { |
| ... | ... | @@ -28305,17 +28310,15 @@ static IrInstGen *ir_analyze_instruction_tag_type(IrAnalyze *ira, IrInstSrcTagTy |
| 28305 | 28310 | } |
| 28306 | 28311 | } |
| 28307 | 28312 | |
| 28308 | | static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstGen *op) { |
| 28313 | static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstGen *op, ZigType **actual_type) { |
| 28309 | 28314 | ZigType *operand_type = ir_resolve_type(ira, op); |
| 28310 | 28315 | if (type_is_invalid(operand_type)) |
| 28311 | 28316 | return ira->codegen->builtin_types.entry_invalid; |
| 28312 | 28317 | |
| 28313 | | if (operand_type->id == ZigTypeIdInt) { |
| 28314 | | if (operand_type->data.integral.bit_count < 8) { |
| 28315 | | ir_add_error(ira, &op->base, |
| 28316 | | buf_sprintf("expected integer type 8 bits or larger, found %" PRIu32 "-bit integer type", |
| 28317 | | operand_type->data.integral.bit_count)); |
| 28318 | | return ira->codegen->builtin_types.entry_invalid; |
| 28318 | *actual_type = nullptr; |
| 28319 | if (operand_type->id == ZigTypeIdInt || operand_type->id == ZigTypeIdEnum) { |
| 28320 | if (operand_type->id == ZigTypeIdEnum) { |
| 28321 | operand_type = operand_type->data.enumeration.tag_int_type; |
| 28319 | 28322 | } |
| 28320 | 28323 | uint32_t max_atomic_bits = target_arch_largest_atomic_bits(ira->codegen->zig_target->arch); |
| 28321 | 28324 | if (operand_type->data.integral.bit_count > max_atomic_bits) { |
| ... | ... | @@ -28324,30 +28327,22 @@ static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstGen *op) { |
| 28324 | 28327 | max_atomic_bits, operand_type->data.integral.bit_count)); |
| 28325 | 28328 | return ira->codegen->builtin_types.entry_invalid; |
| 28326 | 28329 | } |
| 28327 | | if (!is_power_of_2(operand_type->data.integral.bit_count)) { |
| 28328 | | ir_add_error(ira, &op->base, |
| 28329 | | buf_sprintf("%" PRIu32 "-bit integer type is not a power of 2", operand_type->data.integral.bit_count)); |
| 28330 | | return ira->codegen->builtin_types.entry_invalid; |
| 28331 | | } |
| 28332 | | } else if (operand_type->id == ZigTypeIdEnum) { |
| 28333 | | ZigType *int_type = operand_type->data.enumeration.tag_int_type; |
| 28334 | | if (int_type->data.integral.bit_count < 8) { |
| 28335 | | ir_add_error(ira, &op->base, |
| 28336 | | buf_sprintf("expected enum tag type 8 bits or larger, found %" PRIu32 "-bit tag type", |
| 28337 | | int_type->data.integral.bit_count)); |
| 28338 | | return ira->codegen->builtin_types.entry_invalid; |
| 28339 | | } |
| 28340 | | uint32_t max_atomic_bits = target_arch_largest_atomic_bits(ira->codegen->zig_target->arch); |
| 28341 | | if (int_type->data.integral.bit_count > max_atomic_bits) { |
| 28342 | | ir_add_error(ira, &op->base, |
| 28343 | | buf_sprintf("expected %" PRIu32 "-bit enum tag type or smaller, found %" PRIu32 "-bit tag type", |
| 28344 | | max_atomic_bits, int_type->data.integral.bit_count)); |
| 28345 | | return ira->codegen->builtin_types.entry_invalid; |
| 28346 | | } |
| 28347 | | if (!is_power_of_2(int_type->data.integral.bit_count)) { |
| 28348 | | ir_add_error(ira, &op->base, |
| 28349 | | buf_sprintf("%" PRIu32 "-bit enum tag type is not a power of 2", int_type->data.integral.bit_count)); |
| 28350 | | return ira->codegen->builtin_types.entry_invalid; |
| 28330 | auto bit_count = operand_type->data.integral.bit_count; |
| 28331 | bool is_signed = operand_type->data.integral.is_signed; |
| 28332 | if (bit_count < 2 || !is_power_of_2(bit_count)) { |
| 28333 | if (bit_count < 8) { |
| 28334 | *actual_type = get_int_type(ira->codegen, is_signed, 8); |
| 28335 | } else if (bit_count < 16) { |
| 28336 | *actual_type = get_int_type(ira->codegen, is_signed, 16); |
| 28337 | } else if (bit_count < 32) { |
| 28338 | *actual_type = get_int_type(ira->codegen, is_signed, 32); |
| 28339 | } else if (bit_count < 64) { |
| 28340 | *actual_type = get_int_type(ira->codegen, is_signed, 64); |
| 28341 | } else if (bit_count < 128) { |
| 28342 | *actual_type = get_int_type(ira->codegen, is_signed, 128); |
| 28343 | } else { |
| 28344 | zig_unreachable(); |
| 28345 | } |
| 28351 | 28346 | } |
| 28352 | 28347 | } else if (operand_type->id == ZigTypeIdFloat) { |
| 28353 | 28348 | uint32_t max_atomic_bits = target_arch_largest_atomic_bits(ira->codegen->zig_target->arch); |
| ... | ... | @@ -28359,6 +28354,7 @@ static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstGen *op) { |
| 28359 | 28354 | } |
| 28360 | 28355 | } else if (operand_type->id == ZigTypeIdBool) { |
| 28361 | 28356 | // will be treated as u8 |
| 28357 | *actual_type = ira->codegen->builtin_types.entry_u8; |
| 28362 | 28358 | } else { |
| 28363 | 28359 | Error err; |
| 28364 | 28360 | ZigType *operand_ptr_type; |
| ... | ... | @@ -28376,7 +28372,8 @@ static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstGen *op) { |
| 28376 | 28372 | } |
| 28377 | 28373 | |
| 28378 | 28374 | static IrInstGen *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstSrcAtomicRmw *instruction) { |
| 28379 | | ZigType *operand_type = ir_resolve_atomic_operand_type(ira, instruction->operand_type->child); |
| 28375 | ZigType *actual_type; |
| 28376 | ZigType *operand_type = ir_resolve_atomic_operand_type(ira, instruction->operand_type->child, &actual_type); |
| 28380 | 28377 | if (type_is_invalid(operand_type)) |
| 28381 | 28378 | return ira->codegen->invalid_inst_gen; |
| 28382 | 28379 | |
| ... | ... | @@ -28434,11 +28431,12 @@ static IrInstGen *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstSrcAto |
| 28434 | 28431 | } |
| 28435 | 28432 | |
| 28436 | 28433 | return ir_build_atomic_rmw_gen(ira, &instruction->base.base, casted_ptr, casted_operand, op, |
| 28437 | | ordering, operand_type); |
| 28434 | ordering, operand_type, actual_type); |
| 28438 | 28435 | } |
| 28439 | 28436 | |
| 28440 | 28437 | static IrInstGen *ir_analyze_instruction_atomic_load(IrAnalyze *ira, IrInstSrcAtomicLoad *instruction) { |
| 28441 | | ZigType *operand_type = ir_resolve_atomic_operand_type(ira, instruction->operand_type->child); |
| 28438 | ZigType *actual_type; |
| 28439 | ZigType *operand_type = ir_resolve_atomic_operand_type(ira, instruction->operand_type->child, &actual_type); |
| 28442 | 28440 | if (type_is_invalid(operand_type)) |
| 28443 | 28441 | return ira->codegen->invalid_inst_gen; |
| 28444 | 28442 | |
| ... | ... | @@ -28468,11 +28466,12 @@ static IrInstGen *ir_analyze_instruction_atomic_load(IrAnalyze *ira, IrInstSrcAt |
| 28468 | 28466 | return result; |
| 28469 | 28467 | } |
| 28470 | 28468 | |
| 28471 | | return ir_build_atomic_load_gen(ira, &instruction->base.base, casted_ptr, ordering, operand_type); |
| 28469 | return ir_build_atomic_load_gen(ira, &instruction->base.base, casted_ptr, ordering, operand_type, actual_type); |
| 28472 | 28470 | } |
| 28473 | 28471 | |
| 28474 | 28472 | static IrInstGen *ir_analyze_instruction_atomic_store(IrAnalyze *ira, IrInstSrcAtomicStore *instruction) { |
| 28475 | | ZigType *operand_type = ir_resolve_atomic_operand_type(ira, instruction->operand_type->child); |
| 28473 | ZigType *actual_type; |
| 28474 | ZigType *operand_type = ir_resolve_atomic_operand_type(ira, instruction->operand_type->child, &actual_type); |
| 28476 | 28475 | if (type_is_invalid(operand_type)) |
| 28477 | 28476 | return ira->codegen->invalid_inst_gen; |
| 28478 | 28477 | |
| ... | ... | @@ -28511,7 +28510,7 @@ static IrInstGen *ir_analyze_instruction_atomic_store(IrAnalyze *ira, IrInstSrcA |
| 28511 | 28510 | return result; |
| 28512 | 28511 | } |
| 28513 | 28512 | |
| 28514 | | return ir_build_atomic_store_gen(ira, &instruction->base.base, casted_ptr, casted_value, ordering); |
| 28513 | return ir_build_atomic_store_gen(ira, &instruction->base.base, casted_ptr, casted_value, ordering, actual_type); |
| 28515 | 28514 | } |
| 28516 | 28515 | |
| 28517 | 28516 | static IrInstGen *ir_analyze_instruction_save_err_ret_addr(IrAnalyze *ira, IrInstSrcSaveErrRetAddr *instruction) { |