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; diff --git a/std/mem.zig b/std/mem.zig index b1e7a608b2..eec29e9caf 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)); }