authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-03-09 14:24:51-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-03-09 14:24:51-04:00
log52c01840ce36f6ed6528fc62c6f3c1426bdce914
tree9739e8a14b43b22fb40caeeea41309830266b872
parent648f94c0275a85fece347ced013f89ee5eb5d800
parent7db6da7cb81c6b83804171e3791198a687881f43
signaturelock-open Commit is signed but in an unrecognized format.

Merge branch 'LemonBoy-fix-4527'

closes #4531

2 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
1556515565 switch (val->data.x_lazy->id) {
1556615566 case LazyValueIdInvalid:
1556715567 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;
1557015580 return ErrorNone;
15581 }
1557115582 case LazyValueIdSizeOf: {
1557215583 LazyValueSizeOf *lazy_size_of = reinterpret_cast<LazyValueSizeOf *>(val->data.x_lazy);
1557315584 IrAnalyze *ira = lazy_size_of->ira;
test/stage1/behavior/alignof.zig+21
......@@ -15,3 +15,24 @@ test "@alignOf(T) before referencing T" {
1515 comptime expect(@alignOf(Foo) == 4);
1616 }
1717}
18
19test "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}