authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-01-27 14:49:48-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-01-27 14:49:48-07:00
logb50844185991a86bac462346413341b87eda14cd
tree9e6c23c5db7785ae6abba756758345768d523a4f
parent0a265867242757accd9a8dafee2f6cce7c738f29

fix `%%` prefix operator codegen for simple values

closes #93

2 files changed, 17 insertions(+), 1 deletions(-)

src/codegen.cpp+2-1
......@@ -916,11 +916,12 @@ static LLVMValueRef gen_prefix_op_expr(CodeGen *g, AstNode *node) {
916916 TypeTableEntry *child_type = expr_type->data.error.child_type;
917917 // TODO in debug mode, put a panic here if the error is not 0
918918 if (child_type->size_in_bits > 0) {
919 add_debug_source_node(g, node);
919920 LLVMValueRef child_val_ptr = LLVMBuildStructGEP(g->builder, expr_val, 1, "");
920921 if (handle_is_ptr(child_type)) {
921922 return child_val_ptr;
922923 } else {
923 return expr_val;
924 return LLVMBuildLoad(g->builder, child_val_ptr, "");
924925 }
925926 } else {
926927 return nullptr;
test/run_tests.cpp+15
......@@ -1329,6 +1329,21 @@ fn f() -> &void {
13291329pub fn main(args: [][]u8) -> %void {
13301330 const a = f();
13311331 return *a;
1332}
1333 )SOURCE", "OK\n");
1334
1335 add_simple_case("unwrap simple value from error", R"SOURCE(
1336import "std.zig";
1337fn do() -> %isize {
1338 13
1339}
1340
1341pub fn main(args: [][]u8) -> %void {
1342 const i = %%do();
1343 if (i != 13) {
1344 %%stdout.printf("BAD\n");
1345 }
1346 %%stdout.printf("OK\n");
13321347}
13331348 )SOURCE", "OK\n");
13341349}