diff --git a/src/ir.cpp b/src/ir.cpp index 110778fb9..3adf6d1e0 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -15565,9 +15565,20 @@ static Error lazy_cmp_zero(CodeGen *codegen, AstNode *source_node, ZigValue *val switch (val->data.x_lazy->id) { case LazyValueIdInvalid: zig_unreachable(); - case LazyValueIdAlignOf: - *result = CmpGT; + case LazyValueIdAlignOf: { + LazyValueAlignOf *lazy_align_of = reinterpret_cast(val->data.x_lazy); + IrAnalyze *ira = lazy_align_of->ira; + + uint32_t abi_align; + if ((err = type_val_resolve_abi_align(ira->codegen, source_node, lazy_align_of->target_type->value, + &abi_align))) + { + return err; + } + + *result = (abi_align == 0) ? CmpEQ : CmpGT; return ErrorNone; + } case LazyValueIdSizeOf: { LazyValueSizeOf *lazy_size_of = reinterpret_cast(val->data.x_lazy); IrAnalyze *ira = lazy_size_of->ira; diff --git a/test/stage1/behavior/alignof.zig b/test/stage1/behavior/alignof.zig index f923fd935..96114ed56 100644 --- a/test/stage1/behavior/alignof.zig +++ b/test/stage1/behavior/alignof.zig @@ -15,3 +15,24 @@ test "@alignOf(T) before referencing T" { comptime expect(@alignOf(Foo) == 4); } } + +test "comparison of @alignOf(T) against zero" { + { + const T = struct { x: u32 }; + expect(!(@alignOf(T) == 0)); + expect(@alignOf(T) != 0); + expect(!(@alignOf(T) < 0)); + expect(!(@alignOf(T) <= 0)); + expect(@alignOf(T) > 0); + expect(@alignOf(T) >= 0); + } + { + const T = struct {}; + expect(@alignOf(T) == 0); + expect(!(@alignOf(T) != 0)); + expect(!(@alignOf(T) < 0)); + expect(@alignOf(T) <= 0); + expect(!(@alignOf(T) > 0)); + expect(@alignOf(T) >= 0); + } +}