authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-12-10 19:41:01-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-12-10 19:41:01-05:00
log4b1d120f5874a3cad4d05e21e6a3219e48f9b056
tree1a02e1bd50193ce58702eb6cc9efdd7575d07e7e
parentdc2e3465c78411c67eb6d1efd4944b19b0b279f2
parent22dc713a2f6b19ccba31434cfa2bc619c1a2c170

Merge remote-tracking branch 'origin/master' into self-hosted


2 files changed, 14 insertions(+), 2 deletions(-)

src/analyze.cpp+1-1
...@@ -2227,7 +2227,7 @@ static void resolve_union_zero_bits(CodeGen *g, TypeTableEntry *union_type) {...@@ -2227,7 +2227,7 @@ static void resolve_union_zero_bits(CodeGen *g, TypeTableEntry *union_type) {
22272227
2228 tag_type = new_type_table_entry(TypeTableEntryIdEnum);2228 tag_type = new_type_table_entry(TypeTableEntryIdEnum);
2229 buf_resize(&tag_type->name, 0);2229 buf_resize(&tag_type->name, 0);
2230 buf_appendf(&tag_type->name, "@EnumTagType(%s)", buf_ptr(&union_type->name));2230 buf_appendf(&tag_type->name, "@TagType(%s)", buf_ptr(&union_type->name));
2231 tag_type->is_copyable = true;2231 tag_type->is_copyable = true;
2232 tag_type->type_ref = tag_int_type->type_ref;2232 tag_type->type_ref = tag_int_type->type_ref;
2233 tag_type->zero_bits = tag_int_type->zero_bits;2233 tag_type->zero_bits = tag_int_type->zero_bits;
std/mem.zig+13-1
...@@ -8,6 +8,7 @@ pub const Cmp = math.Cmp;...@@ -8,6 +8,7 @@ pub const Cmp = math.Cmp;
8pub const Allocator = struct {8pub const Allocator = struct {
9 /// Allocate byte_count bytes and return them in a slice, with the9 /// Allocate byte_count bytes and return them in a slice, with the
10 /// slice's pointer aligned at least to alignment bytes.10 /// slice's pointer aligned at least to alignment bytes.
11 /// The returned newly allocated memory is undefined.
11 allocFn: fn (self: &Allocator, byte_count: usize, alignment: u29) -> %[]u8,12 allocFn: fn (self: &Allocator, byte_count: usize, alignment: u29) -> %[]u8,
1213
13 /// If `new_byte_count > old_mem.len`:14 /// If `new_byte_count > old_mem.len`:
...@@ -17,6 +18,8 @@ pub const Allocator = struct {...@@ -17,6 +18,8 @@ pub const Allocator = struct {
17 /// If `new_byte_count <= old_mem.len`:18 /// If `new_byte_count <= old_mem.len`:
18 /// * this function must return successfully. 19 /// * this function must return successfully.
19 /// * alignment <= alignment of old_mem.ptr20 /// * alignment <= alignment of old_mem.ptr
21 ///
22 /// The returned newly allocated memory is undefined.
20 reallocFn: fn (self: &Allocator, old_mem: []u8, new_byte_count: usize, alignment: u29) -> %[]u8,23 reallocFn: fn (self: &Allocator, old_mem: []u8, new_byte_count: usize, alignment: u29) -> %[]u8,
2124
22 /// Guaranteed: `old_mem.len` is the same as what was returned from `allocFn` or `reallocFn`25 /// Guaranteed: `old_mem.len` is the same as what was returned from `allocFn` or `reallocFn`
...@@ -40,6 +43,10 @@ pub const Allocator = struct {...@@ -40,6 +43,10 @@ pub const Allocator = struct {
40 {43 {
41 const byte_count = %return math.mul(usize, @sizeOf(T), n);44 const byte_count = %return math.mul(usize, @sizeOf(T), n);
42 const byte_slice = %return self.allocFn(self, byte_count, alignment);45 const byte_slice = %return self.allocFn(self, byte_count, alignment);
46 // This loop should get optimized out in ReleaseFast mode
47 for (byte_slice) |*byte| {
48 *byte = undefined;
49 }
43 return ([]align(alignment) T)(@alignCast(alignment, byte_slice));50 return ([]align(alignment) T)(@alignCast(alignment, byte_slice));
44 }51 }
4552
...@@ -54,8 +61,13 @@ pub const Allocator = struct {...@@ -54,8 +61,13 @@ pub const Allocator = struct {
54 return self.alloc(T, n);61 return self.alloc(T, n);
55 }62 }
5663
64 const old_byte_slice = ([]u8)(old_mem);
57 const byte_count = %return math.mul(usize, @sizeOf(T), n);65 const byte_count = %return math.mul(usize, @sizeOf(T), n);
58 const byte_slice = %return self.reallocFn(self, ([]u8)(old_mem), byte_count, alignment);66 const byte_slice = %return self.reallocFn(self, old_byte_slice, byte_count, alignment);
67 // This loop should get optimized out in ReleaseFast mode
68 for (byte_slice[old_byte_slice.len..]) |*byte| {
69 *byte = undefined;
70 }
59 return ([]T)(@alignCast(alignment, byte_slice));71 return ([]T)(@alignCast(alignment, byte_slice));
60 }72 }
6173