| author | |
| committer | |
| log | 52c01840ce36f6ed6528fc62c6f3c1426bdce914 |
| tree | 9739e8a14b43b22fb40caeeea41309830266b872 |
| parent | 648f94c0275a85fece347ced013f89ee5eb5d800 |
| parent | 7db6da7cb81c6b83804171e3791198a687881f43 |
| signature |
closes #45312 files changed, 34 insertions(+), 2 deletions(-)
src/ir.cpp+13-2| ... | ... | @@ -15565,9 +15565,20 @@ static Error lazy_cmp_zero(CodeGen *codegen, AstNode *source_node, ZigValue *val |
| 15565 | 15565 | switch (val->data.x_lazy->id) { |
| 15566 | 15566 | case LazyValueIdInvalid: |
| 15567 | 15567 | zig_unreachable(); |
| 15568 | case LazyValueIdAlignOf: | |
| 15569 | *result = CmpGT; | |
| 15568 | case LazyValueIdAlignOf: { | |
| 15569 | LazyValueAlignOf *lazy_align_of = reinterpret_cast<LazyValueAlignOf *>(val->data.x_lazy); | |
| 15570 | IrAnalyze *ira = lazy_align_of->ira; | |
| 15571 | ||
| 15572 | bool is_zero_bits; | |
| 15573 | if ((err = type_val_resolve_zero_bits(ira->codegen, lazy_align_of->target_type->value, | |
| 15574 | nullptr, nullptr, &is_zero_bits))) | |
| 15575 | { | |
| 15576 | return err; | |
| 15577 | } | |
| 15578 | ||
| 15579 | *result = is_zero_bits ? CmpEQ : CmpGT; | |
| 15570 | 15580 | return ErrorNone; |
| 15581 | } | |
| 15571 | 15582 | case LazyValueIdSizeOf: { |
| 15572 | 15583 | LazyValueSizeOf *lazy_size_of = reinterpret_cast<LazyValueSizeOf *>(val->data.x_lazy); |
| 15573 | 15584 | IrAnalyze *ira = lazy_size_of->ira; |
test/stage1/behavior/alignof.zig+21| ... | ... | @@ -15,3 +15,24 @@ test "@alignOf(T) before referencing T" { |
| 15 | 15 | comptime expect(@alignOf(Foo) == 4); |
| 16 | 16 | } |
| 17 | 17 | } |
| 18 | ||
| 19 | test "comparison of @alignOf(T) against zero" { | |
| 20 | { | |
| 21 | const T = struct { x: u32 }; | |
| 22 | expect(!(@alignOf(T) == 0)); | |
| 23 | expect(@alignOf(T) != 0); | |
| 24 | expect(!(@alignOf(T) < 0)); | |
| 25 | expect(!(@alignOf(T) <= 0)); | |
| 26 | expect(@alignOf(T) > 0); | |
| 27 | expect(@alignOf(T) >= 0); | |
| 28 | } | |
| 29 | { | |
| 30 | const T = struct {}; | |
| 31 | expect(@alignOf(T) == 0); | |
| 32 | expect(!(@alignOf(T) != 0)); | |
| 33 | expect(!(@alignOf(T) < 0)); | |
| 34 | expect(@alignOf(T) <= 0); | |
| 35 | expect(!(@alignOf(T) > 0)); | |
| 36 | expect(@alignOf(T) >= 0); | |
| 37 | } | |
| 38 | } |