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) {
22272227
22282228 tag_type = new_type_table_entry(TypeTableEntryIdEnum);
22292229 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));
22312231 tag_type->is_copyable = true;
22322232 tag_type->type_ref = tag_int_type->type_ref;
22332233 tag_type->zero_bits = tag_int_type->zero_bits;
std/mem.zig+13-1
......@@ -8,6 +8,7 @@ pub const Cmp = math.Cmp;
88pub const Allocator = struct {
99 /// Allocate byte_count bytes and return them in a slice, with the
1010 /// slice's pointer aligned at least to alignment bytes.
11 /// The returned newly allocated memory is undefined.
1112 allocFn: fn (self: &Allocator, byte_count: usize, alignment: u29) -> %[]u8,
1213
1314 /// If `new_byte_count > old_mem.len`:
......@@ -17,6 +18,8 @@ pub const Allocator = struct {
1718 /// If `new_byte_count <= old_mem.len`:
1819 /// * this function must return successfully.
1920 /// * alignment <= alignment of old_mem.ptr
21 ///
22 /// The returned newly allocated memory is undefined.
2023 reallocFn: fn (self: &Allocator, old_mem: []u8, new_byte_count: usize, alignment: u29) -> %[]u8,
2124
2225 /// Guaranteed: `old_mem.len` is the same as what was returned from `allocFn` or `reallocFn`
......@@ -40,6 +43,10 @@ pub const Allocator = struct {
4043 {
4144 const byte_count = %return math.mul(usize, @sizeOf(T), n);
4245 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 }
4350 return ([]align(alignment) T)(@alignCast(alignment, byte_slice));
4451 }
4552
......@@ -54,8 +61,13 @@ pub const Allocator = struct {
5461 return self.alloc(T, n);
5562 }
5663
64 const old_byte_slice = ([]u8)(old_mem);
5765 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 }
5971 return ([]T)(@alignCast(alignment, byte_slice));
6072 }
6173