From 990db3c35a798a6e51dbbbc1696f3fe78c7a0faf Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Sun, 10 Dec 2017 15:03:57 -0500 Subject: [PATCH 1/2] rename @EnumTagType to @TagType in type names --- src/analyze.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/analyze.cpp b/src/analyze.cpp index 431b64f984..1d5d5e4790 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -2227,7 +2227,7 @@ static void resolve_union_zero_bits(CodeGen *g, TypeTableEntry *union_type) { tag_type = new_type_table_entry(TypeTableEntryIdEnum); buf_resize(&tag_type->name, 0); - buf_appendf(&tag_type->name, "@EnumTagType(%s)", buf_ptr(&union_type->name)); + buf_appendf(&tag_type->name, "@TagType(%s)", buf_ptr(&union_type->name)); tag_type->is_copyable = true; tag_type->type_ref = tag_int_type->type_ref; tag_type->zero_bits = tag_int_type->zero_bits; From 22dc713a2f6b19ccba31434cfa2bc619c1a2c170 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Sun, 10 Dec 2017 15:38:05 -0500 Subject: [PATCH 2/2] mem.Allocator initializes bytes to undefined --- std/mem.zig | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/std/mem.zig b/std/mem.zig index e99675d248..2e6bd6ec85 100644 --- a/std/mem.zig +++ b/std/mem.zig @@ -8,6 +8,7 @@ pub const Cmp = math.Cmp; pub const Allocator = struct { /// Allocate byte_count bytes and return them in a slice, with the /// slice's pointer aligned at least to alignment bytes. + /// The returned newly allocated memory is undefined. allocFn: fn (self: &Allocator, byte_count: usize, alignment: u29) -> %[]u8, /// If `new_byte_count > old_mem.len`: @@ -17,6 +18,8 @@ pub const Allocator = struct { /// If `new_byte_count <= old_mem.len`: /// * this function must return successfully. /// * alignment <= alignment of old_mem.ptr + /// + /// The returned newly allocated memory is undefined. reallocFn: fn (self: &Allocator, old_mem: []u8, new_byte_count: usize, alignment: u29) -> %[]u8, /// Guaranteed: `old_mem.len` is the same as what was returned from `allocFn` or `reallocFn` @@ -40,6 +43,10 @@ pub const Allocator = struct { { const byte_count = %return math.mul(usize, @sizeOf(T), n); const byte_slice = %return self.allocFn(self, byte_count, alignment); + // This loop should get optimized out in ReleaseFast mode + for (byte_slice) |*byte| { + *byte = undefined; + } return ([]align(alignment) T)(@alignCast(alignment, byte_slice)); } @@ -54,8 +61,13 @@ pub const Allocator = struct { return self.alloc(T, n); } + const old_byte_slice = ([]u8)(old_mem); const byte_count = %return math.mul(usize, @sizeOf(T), n); - const byte_slice = %return self.reallocFn(self, ([]u8)(old_mem), byte_count, alignment); + const byte_slice = %return self.reallocFn(self, old_byte_slice, byte_count, alignment); + // This loop should get optimized out in ReleaseFast mode + for (byte_slice[old_byte_slice.len..]) |*byte| { + *byte = undefined; + } return ([]T)(@alignCast(alignment, byte_slice)); }