diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2019-06-19 16:16:47 -0400 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2019-06-19 16:16:47 -0400 |
| commit | 974db231a08731f642dbf72d716f669fed2bd2ab (patch) | |
| tree | 209e1a0766c98f1a1a471fbd0eab97d3bbb093dc | |
| parent | e36680d3bd08fceb3e976edeafae60ce6d577342 (diff) | |
| download | zig-974db231a08731f642dbf72d716f669fed2bd2ab.tar.gz zig-974db231a08731f642dbf72d716f669fed2bd2ab.zip | |
fix extraneous nested union field instruction
| -rw-r--r-- | src/codegen.cpp | 7 | ||||
| -rw-r--r-- | test/stage1/behavior.zig | 2 | ||||
| -rw-r--r-- | test/stage1/behavior/enum.zig | 32 |
3 files changed, 23 insertions, 18 deletions
diff --git a/src/codegen.cpp b/src/codegen.cpp index 8f3a8df451..bd3bae66fc 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -3853,6 +3853,9 @@ static LLVMValueRef ir_render_struct_field_ptr(CodeGen *g, IrExecutable *executa static LLVMValueRef ir_render_union_field_ptr(CodeGen *g, IrExecutable *executable, IrInstructionUnionFieldPtr *instruction) { + if (instruction->base.value.special != ConstValSpecialRuntime) + return nullptr; + ZigType *union_ptr_type = instruction->union_ptr->value.type; assert(union_ptr_type->id == ZigTypeIdPointer); ZigType *union_type = union_ptr_type->data.pointer.child_type; @@ -4077,6 +4080,9 @@ static LLVMValueRef ir_render_test_non_null(CodeGen *g, IrExecutable *executable static LLVMValueRef ir_render_optional_unwrap_ptr(CodeGen *g, IrExecutable *executable, IrInstructionOptionalUnwrapPtr *instruction) { + if (instruction->base.value.special != ConstValSpecialRuntime) + return nullptr; + ZigType *ptr_type = instruction->base_ptr->value.type; assert(ptr_type->id == ZigTypeIdPointer); ZigType *maybe_type = ptr_type->data.pointer.child_type; @@ -5750,7 +5756,6 @@ static void ir_render(CodeGen *g, ZigFn *fn_entry) { assert(executable->basic_block_list.length > 0); for (size_t block_i = 0; block_i < executable->basic_block_list.length; block_i += 1) { IrBasicBlock *current_block = executable->basic_block_list.at(block_i); - //assert(current_block->ref_count > 0); assert(current_block->llvm_block); LLVMPositionBuilderAtEnd(g->builder, current_block->llvm_block); for (size_t instr_i = 0; instr_i < current_block->instruction_list.length; instr_i += 1) { diff --git a/test/stage1/behavior.zig b/test/stage1/behavior.zig index 5ad6b94f3f..0e93290cc4 100644 --- a/test/stage1/behavior.zig +++ b/test/stage1/behavior.zig @@ -45,7 +45,7 @@ comptime { //_ = @import("behavior/coroutine_await_struct.zig"); //_ = @import("behavior/coroutines.zig"); _ = @import("behavior/defer.zig"); - _ = @import("behavior/enum.zig"); // TODO + _ = @import("behavior/enum.zig"); _ = @import("behavior/enum_with_members.zig"); _ = @import("behavior/error.zig"); // TODO _ = @import("behavior/eval.zig"); diff --git a/test/stage1/behavior/enum.zig b/test/stage1/behavior/enum.zig index e06a075974..51f4f0e196 100644 --- a/test/stage1/behavior/enum.zig +++ b/test/stage1/behavior/enum.zig @@ -1,22 +1,22 @@ const expect = @import("std").testing.expect; const mem = @import("std").mem; -//test "enum type" { -// const foo1 = Foo{ .One = 13 }; -// const foo2 = Foo{ -// .Two = Point{ -// .x = 1234, -// .y = 5678, -// }, -// }; -// const bar = Bar.B; -// -// expect(bar == Bar.B); -// expect(@memberCount(Foo) == 3); -// expect(@memberCount(Bar) == 4); -// expect(@sizeOf(Foo) == @sizeOf(FooNoVoid)); -// expect(@sizeOf(Bar) == 1); -//} +test "enum type" { + const foo1 = Foo{ .One = 13 }; + const foo2 = Foo{ + .Two = Point{ + .x = 1234, + .y = 5678, + }, + }; + const bar = Bar.B; + + expect(bar == Bar.B); + expect(@memberCount(Foo) == 3); + expect(@memberCount(Bar) == 4); + expect(@sizeOf(Foo) == @sizeOf(FooNoVoid)); + expect(@sizeOf(Bar) == 1); +} test "enum as return value" { switch (returnAnInt(13)) { |
