| author | |
| committer | |
| log | 5fc95c2a538b10ad346273112b1d4ed5371f8135 |
| tree | f0700978c5f7f51e37b45b74c9d79e66d3afcb1c |
| parent | 46033a2128b09ed15f38f6ed2602bf80989a770f |
7 files changed, 123 insertions(+), 116 deletions(-)
src/ir.cpp+1-1| ... | @@ -5462,7 +5462,7 @@ static TypeTableEntry *ir_analyze_ref(IrAnalyze *ira, IrInstruction *source_inst | ... | @@ -5462,7 +5462,7 @@ static TypeTableEntry *ir_analyze_ref(IrAnalyze *ira, IrInstruction *source_inst |
| 5462 | ConstExprValue *val = ir_resolve_const(ira, value, UndefBad); | 5462 | ConstExprValue *val = ir_resolve_const(ira, value, UndefBad); |
| 5463 | if (!val) | 5463 | if (!val) |
| 5464 | return ira->codegen->builtin_types.entry_invalid; | 5464 | return ira->codegen->builtin_types.entry_invalid; |
| 5465 | bool ptr_is_const = true; | 5465 | bool ptr_is_const = false; |
| 5466 | return ir_analyze_const_ptr(ira, source_instruction, val, value->type_entry, | 5466 | return ir_analyze_const_ptr(ira, source_instruction, val, value->type_entry, |
| 5467 | false, ConstPtrSpecialNone, ptr_is_const); | 5467 | false, ConstPtrSpecialNone, ptr_is_const); |
| 5468 | } | 5468 | } |
test/cases3/array.zig created+31| ... | @@ -0,0 +1,31 @@ | ||
| 1 | fn arrays() { | ||
| 2 | @setFnTest(this); | ||
| 3 | |||
| 4 | var array : [5]u32 = undefined; | ||
| 5 | |||
| 6 | var i : u32 = 0; | ||
| 7 | while (i < 5) { | ||
| 8 | array[i] = i + 1; | ||
| 9 | i = array[i]; | ||
| 10 | } | ||
| 11 | |||
| 12 | i = 0; | ||
| 13 | var accumulator = u32(0); | ||
| 14 | while (i < 5) { | ||
| 15 | accumulator += array[i]; | ||
| 16 | |||
| 17 | i += 1; | ||
| 18 | } | ||
| 19 | |||
| 20 | assert(accumulator == 15); | ||
| 21 | assert(getArrayLen(array) == 5); | ||
| 22 | } | ||
| 23 | fn getArrayLen(a: []u32) -> usize { | ||
| 24 | a.len | ||
| 25 | } | ||
| 26 | |||
| 27 | // TODO const assert = @import("std").debug.assert; | ||
| 28 | fn assert(ok: bool) { | ||
| 29 | if (!ok) | ||
| 30 | @unreachable(); | ||
| 31 | } | ||
test/cases3/fn.zig+30| ... | @@ -32,6 +32,36 @@ fn voidFun(a: i32, b: void, c: i32, d: void) { | ... | @@ -32,6 +32,36 @@ fn voidFun(a: i32, b: void, c: i32, d: void) { |
| 32 | } | 32 | } |
| 33 | 33 | ||
| 34 | 34 | ||
| 35 | fn mutableLocalVariables() { | ||
| 36 | @setFnTest(this); | ||
| 37 | |||
| 38 | var zero : i32 = 0; | ||
| 39 | assert(zero == 0); | ||
| 40 | |||
| 41 | var i = i32(0); | ||
| 42 | while (i != 3) { | ||
| 43 | i += 1; | ||
| 44 | } | ||
| 45 | assert(i == 3); | ||
| 46 | } | ||
| 47 | |||
| 48 | fn separateBlockScopes() { | ||
| 49 | @setFnTest(this); | ||
| 50 | |||
| 51 | { | ||
| 52 | const no_conflict : i32 = 5; | ||
| 53 | assert(no_conflict == 5); | ||
| 54 | } | ||
| 55 | |||
| 56 | const c = { | ||
| 57 | const no_conflict = i32(10); | ||
| 58 | no_conflict | ||
| 59 | }; | ||
| 60 | assert(c == 10); | ||
| 61 | } | ||
| 62 | |||
| 63 | |||
| 64 | |||
| 35 | // TODO const assert = @import("std").debug.assert; | 65 | // TODO const assert = @import("std").debug.assert; |
| 36 | fn assert(ok: bool) { | 66 | fn assert(ok: bool) { |
| 37 | if (!ok) | 67 | if (!ok) |
test/cases3/math.zig+19| ... | @@ -50,6 +50,25 @@ fn countTrailingZeroes() { | ... | @@ -50,6 +50,25 @@ fn countTrailingZeroes() { |
| 50 | assert(@ctz(u8(0b00000000)) == 8); | 50 | assert(@ctz(u8(0b00000000)) == 8); |
| 51 | } | 51 | } |
| 52 | 52 | ||
| 53 | fn modifyOperators() { | ||
| 54 | @setFnTest(this); | ||
| 55 | |||
| 56 | var i : i32 = 0; | ||
| 57 | i += 5; assert(i == 5); | ||
| 58 | i -= 2; assert(i == 3); | ||
| 59 | i *= 20; assert(i == 60); | ||
| 60 | i /= 3; assert(i == 20); | ||
| 61 | i %= 11; assert(i == 9); | ||
| 62 | i <<= 1; assert(i == 18); | ||
| 63 | i >>= 2; assert(i == 4); | ||
| 64 | i = 6; | ||
| 65 | i &= 5; assert(i == 4); | ||
| 66 | i ^= 6; assert(i == 2); | ||
| 67 | i = 6; | ||
| 68 | i |= 3; assert(i == 7); | ||
| 69 | } | ||
| 70 | |||
| 71 | |||
| 53 | // TODO const assert = @import("std").debug.assert; | 72 | // TODO const assert = @import("std").debug.assert; |
| 54 | fn assert(ok: bool) { | 73 | fn assert(ok: bool) { |
| 55 | if (!ok) | 74 | if (!ok) |
test/cases3/struct.zig+41| ... | @@ -21,6 +21,47 @@ fn invokeStaticMethodInGlobalScope() { | ... | @@ -21,6 +21,47 @@ fn invokeStaticMethodInGlobalScope() { |
| 21 | assert(should_be_11 == 11); | 21 | assert(should_be_11 == 11); |
| 22 | } | 22 | } |
| 23 | 23 | ||
| 24 | fn voidStructFields() { | ||
| 25 | @setFnTest(this); | ||
| 26 | |||
| 27 | const foo = VoidStructFieldsFoo { | ||
| 28 | .a = void{}, | ||
| 29 | .b = 1, | ||
| 30 | .c = void{}, | ||
| 31 | }; | ||
| 32 | assert(foo.b == 1); | ||
| 33 | assert(@sizeOf(VoidStructFieldsFoo) == 4); | ||
| 34 | } | ||
| 35 | const VoidStructFieldsFoo = struct { | ||
| 36 | a : void, | ||
| 37 | b : i32, | ||
| 38 | c : void, | ||
| 39 | }; | ||
| 40 | |||
| 41 | |||
| 42 | pub fn structs() { | ||
| 43 | @setFnTest(this); | ||
| 44 | |||
| 45 | var foo: StructFoo = undefined; | ||
| 46 | @memset((&u8)(&foo), 0, @sizeOf(StructFoo)); | ||
| 47 | foo.a += 1; | ||
| 48 | foo.b = foo.a == 1; | ||
| 49 | testFoo(foo); | ||
| 50 | testMutation(&foo); | ||
| 51 | assert(foo.c == 100); | ||
| 52 | } | ||
| 53 | const StructFoo = struct { | ||
| 54 | a : i32, | ||
| 55 | b : bool, | ||
| 56 | c : f32, | ||
| 57 | }; | ||
| 58 | fn testFoo(foo : StructFoo) { | ||
| 59 | assert(foo.b); | ||
| 60 | } | ||
| 61 | fn testMutation(foo : &StructFoo) { | ||
| 62 | foo.c = 100; | ||
| 63 | } | ||
| 64 | |||
| 24 | 65 | ||
| 25 | 66 | ||
| 26 | // TODO const assert = @import("std").debug.assert; | 67 | // TODO const assert = @import("std").debug.assert; |
test/self_hosted.zig-115| ... | @@ -17,121 +17,6 @@ const test_this = @import("cases/this.zig"); | ... | @@ -17,121 +17,6 @@ const test_this = @import("cases/this.zig"); |
| 17 | 17 | ||
| 18 | 18 | ||
| 19 | 19 | ||
| 20 | fn mutableLocalVariables() { | ||
| 21 | @setFnTest(this, true); | ||
| 22 | |||
| 23 | var zero : i32 = 0; | ||
| 24 | assert(zero == 0); | ||
| 25 | |||
| 26 | var i = i32(0); | ||
| 27 | while (i != 3) { | ||
| 28 | i += 1; | ||
| 29 | } | ||
| 30 | assert(i == 3); | ||
| 31 | } | ||
| 32 | |||
| 33 | fn arrays() { | ||
| 34 | @setFnTest(this, true); | ||
| 35 | |||
| 36 | var array : [5]u32 = undefined; | ||
| 37 | |||
| 38 | var i : u32 = 0; | ||
| 39 | while (i < 5) { | ||
| 40 | array[i] = i + 1; | ||
| 41 | i = array[i]; | ||
| 42 | } | ||
| 43 | |||
| 44 | i = 0; | ||
| 45 | var accumulator = u32(0); | ||
| 46 | while (i < 5) { | ||
| 47 | accumulator += array[i]; | ||
| 48 | |||
| 49 | i += 1; | ||
| 50 | } | ||
| 51 | |||
| 52 | assert(accumulator == 15); | ||
| 53 | assert(getArrayLen(array) == 5); | ||
| 54 | } | ||
| 55 | fn getArrayLen(a: []u32) -> usize { | ||
| 56 | a.len | ||
| 57 | } | ||
| 58 | |||
| 59 | fn modifyOperators() { | ||
| 60 | @setFnTest(this, true); | ||
| 61 | |||
| 62 | var i : i32 = 0; | ||
| 63 | i += 5; assert(i == 5); | ||
| 64 | i -= 2; assert(i == 3); | ||
| 65 | i *= 20; assert(i == 60); | ||
| 66 | i /= 3; assert(i == 20); | ||
| 67 | i %= 11; assert(i == 9); | ||
| 68 | i <<= 1; assert(i == 18); | ||
| 69 | i >>= 2; assert(i == 4); | ||
| 70 | i = 6; | ||
| 71 | i &= 5; assert(i == 4); | ||
| 72 | i ^= 6; assert(i == 2); | ||
| 73 | i = 6; | ||
| 74 | i |= 3; assert(i == 7); | ||
| 75 | } | ||
| 76 | |||
| 77 | |||
| 78 | fn separateBlockScopes() { | ||
| 79 | @setFnTest(this, true); | ||
| 80 | |||
| 81 | { | ||
| 82 | const no_conflict : i32 = 5; | ||
| 83 | assert(no_conflict == 5); | ||
| 84 | } | ||
| 85 | |||
| 86 | const c = { | ||
| 87 | const no_conflict = i32(10); | ||
| 88 | no_conflict | ||
| 89 | }; | ||
| 90 | assert(c == 10); | ||
| 91 | } | ||
| 92 | |||
| 93 | |||
| 94 | fn voidStructFields() { | ||
| 95 | @setFnTest(this, true); | ||
| 96 | |||
| 97 | const foo = VoidStructFieldsFoo { | ||
| 98 | .a = void{}, | ||
| 99 | .b = 1, | ||
| 100 | .c = void{}, | ||
| 101 | }; | ||
| 102 | assert(foo.b == 1); | ||
| 103 | assert(@sizeOf(VoidStructFieldsFoo) == 4); | ||
| 104 | } | ||
| 105 | struct VoidStructFieldsFoo { | ||
| 106 | a : void, | ||
| 107 | b : i32, | ||
| 108 | c : void, | ||
| 109 | } | ||
| 110 | |||
| 111 | |||
| 112 | |||
| 113 | pub fn structs() { | ||
| 114 | @setFnTest(this, true); | ||
| 115 | |||
| 116 | var foo : StructFoo = undefined; | ||
| 117 | @memset(&foo, 0, @sizeOf(StructFoo)); | ||
| 118 | foo.a += 1; | ||
| 119 | foo.b = foo.a == 1; | ||
| 120 | testFoo(foo); | ||
| 121 | testMutation(&foo); | ||
| 122 | assert(foo.c == 100); | ||
| 123 | } | ||
| 124 | struct StructFoo { | ||
| 125 | a : i32, | ||
| 126 | b : bool, | ||
| 127 | c : f32, | ||
| 128 | } | ||
| 129 | fn testFoo(foo : StructFoo) { | ||
| 130 | assert(foo.b); | ||
| 131 | } | ||
| 132 | fn testMutation(foo : &StructFoo) { | ||
| 133 | foo.c = 100; | ||
| 134 | } | ||
| 135 | struct Node { | 20 | struct Node { |
| 136 | val: Val, | 21 | val: Val, |
| 137 | next: &Node, | 22 | next: &Node, |
test/self_hosted3.zig+1| ... | @@ -1,4 +1,5 @@ | ... | @@ -1,4 +1,5 @@ |
| 1 | // TODO '_' identifier for unused variable bindings | 1 | // TODO '_' identifier for unused variable bindings |
| 2 | const test_array = @import("cases3/array.zig"); | ||
| 2 | const test_atomics = @import("cases3/atomics.zig"); | 3 | const test_atomics = @import("cases3/atomics.zig"); |
| 3 | const test_defer = @import("cases3/defer.zig"); | 4 | const test_defer = @import("cases3/defer.zig"); |
| 4 | const test_enum = @import("cases3/enum.zig"); | 5 | const test_enum = @import("cases3/enum.zig"); |