authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2020-02-23 09:44:19+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-03-09 14:05:38-04:00
log14bbb828326a8b08cf6680a44d992e64a5de34f5
tree41f2a9285ed5324d7f45f86e3657d93346899fa6
parent648f94c0275a85fece347ced013f89ee5eb5d800
signaturelock-open Commit is signed but in an unrecognized format.

ir: Fix lazy comparison between @alignOf and zero

Closes #4527

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...@@ -15565,9 +15565,20 @@ static Error lazy_cmp_zero(CodeGen *codegen, AstNode *source_node, ZigValue *val
15565 switch (val->data.x_lazy->id) {15565 switch (val->data.x_lazy->id) {
15566 case LazyValueIdInvalid:15566 case LazyValueIdInvalid:
15567 zig_unreachable();15567 zig_unreachable();
15568 case LazyValueIdAlignOf:15568 case LazyValueIdAlignOf: {
15569 *result = CmpGT;15569 LazyValueAlignOf *lazy_align_of = reinterpret_cast<LazyValueAlignOf *>(val->data.x_lazy);
15570 IrAnalyze *ira = lazy_align_of->ira;
15571
15572 uint32_t abi_align;
15573 if ((err = type_val_resolve_abi_align(ira->codegen, source_node, lazy_align_of->target_type->value,
15574 &abi_align)))
15575 {
15576 return err;
15577 }
15578
15579 *result = (abi_align == 0) ? CmpEQ : CmpGT;
15570 return ErrorNone;15580 return ErrorNone;
15581 }
15571 case LazyValueIdSizeOf: {15582 case LazyValueIdSizeOf: {
15572 LazyValueSizeOf *lazy_size_of = reinterpret_cast<LazyValueSizeOf *>(val->data.x_lazy);15583 LazyValueSizeOf *lazy_size_of = reinterpret_cast<LazyValueSizeOf *>(val->data.x_lazy);
15573 IrAnalyze *ira = lazy_size_of->ira;15584 IrAnalyze *ira = lazy_size_of->ira;
test/stage1/behavior/alignof.zig+21
...@@ -15,3 +15,24 @@ test "@alignOf(T) before referencing T" {...@@ -15,3 +15,24 @@ test "@alignOf(T) before referencing T" {
15 comptime expect(@alignOf(Foo) == 4);15 comptime expect(@alignOf(Foo) == 4);
16 }16 }
17}17}
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}