zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 8583fd7f9f96887fe685354662b1fc076ebeb031 (tree)
parent 8ad75a9bf3a7fa9782bf17165fa6d7dc842efb51
Author: Andrew Kelley <superjoe30@gmail.com>
Date:   Sun, 24 Apr 2016 12:27:59 -0700

add codegen for pointer comparison

see #145

Diffstat:
Msrc/codegen.cpp | 4+++-
Mtest/self_hosted.zig | 11+++++++++++
2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/src/codegen.cpp b/src/codegen.cpp @@ -1480,7 +1480,9 @@ static LLVMValueRef gen_cmp_expr(CodeGen *g, AstNode *node) { } else { zig_unreachable(); } - } else if (op1_type->id == TypeTableEntryIdPureError) { + } else if (op1_type->id == TypeTableEntryIdPureError || + op1_type->id == TypeTableEntryIdPointer) + { LLVMIntPredicate pred = cmp_op_to_int_predicate(node->data.bin_op_expr.bin_op, false); return LLVMBuildICmp(g->builder, pred, val1, val2, ""); } else { diff --git a/test/self_hosted.zig b/test/self_hosted.zig @@ -1322,3 +1322,14 @@ fn pass_slice_of_empty_struct_to_fn() { fn test_pass_slice_of_empty_struct_to_fn(slice: []EmptyStruct2) -> isize { slice.len } + + +#attribute("test") +fn pointer_comparison() { + const a = ([]u8)("a"); + const b = &a; + assert(ptr_eql(b, b)); +} +fn ptr_eql(a: &[]u8, b: &[]u8) -> bool { + a == b +}