| author | |
| committer | |
| log | e9280c86a1fc79aec5936bb21c9469657555a7ed |
| tree | d46be8ed77adda6487f49f25d2d43a36ec98b18c |
| parent | 010b725bdef57eee969668087c8737e053b10e9f |
See #372 files changed, 19 insertions(+), 0 deletions(-)
src/ir.cpp+9| ... | ... | @@ -13488,6 +13488,15 @@ static TypeTableEntry *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstruct |
| 13488 | 13488 | |
| 13489 | 13489 | TypeTableEntry *child_type = ptr->value.type->data.pointer.child_type; |
| 13490 | 13490 | |
| 13491 | uint32_t align_bytes = ptr->value.type->data.pointer.alignment; | |
| 13492 | uint64_t size_bytes = type_size(ira->codegen, child_type); | |
| 13493 | if (align_bytes < size_bytes) { | |
| 13494 | ir_add_error(ira, instruction->ptr, | |
| 13495 | buf_sprintf("expected pointer alignment of at least %" ZIG_PRI_u64 ", found %" PRIu32, | |
| 13496 | size_bytes, align_bytes)); | |
| 13497 | return ira->codegen->builtin_types.entry_invalid; | |
| 13498 | } | |
| 13499 | ||
| 13491 | 13500 | IrInstruction *casted_cmp_value = ir_implicit_cast(ira, cmp_value, child_type); |
| 13492 | 13501 | if (type_is_invalid(casted_cmp_value->value.type)) |
| 13493 | 13502 | return ira->codegen->builtin_types.entry_invalid; |
test/compile_errors.zig+10| ... | ... | @@ -2051,4 +2051,14 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 2051 | 2051 | , |
| 2052 | 2052 | ".tmp_source.zig:2:35: error: expected type 'fn() align 8 -> i32', found 'fn() align 4 -> i32'"); |
| 2053 | 2053 | |
| 2054 | cases.add("passing a not-aligned-enough pointer to cmpxchg", | |
| 2055 | \\const AtomicOrder = @import("builtin").AtomicOrder; | |
| 2056 | \\export fn entry() -> bool { | |
| 2057 | \\ var x: i32 align 1 = 1234; | |
| 2058 | \\ while (!@cmpxchg(&x, 1234, 5678, AtomicOrder.SeqCst, AtomicOrder.SeqCst)) {} | |
| 2059 | \\ return x == 5678; | |
| 2060 | \\} | |
| 2061 | , | |
| 2062 | ".tmp_source.zig:4:23: error: expected pointer alignment of at least 4, found 1"); | |
| 2063 | ||
| 2054 | 2064 | } |