From 89a5decc33e532eca4ae3739ae89db508a700a8d Mon Sep 17 00:00:00 2001 From: gingerBill Date: Wed, 13 Nov 2024 18:32:50 +0000 Subject: [PATCH] Keep ASAN happy on type assertions --- src/llvm_backend_utility.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/llvm_backend_utility.cpp b/src/llvm_backend_utility.cpp index 6367d0118..e6049da84 100644 --- a/src/llvm_backend_utility.cpp +++ b/src/llvm_backend_utility.cpp @@ -124,8 +124,16 @@ gb_internal void lb_mem_zero_ptr(lbProcedure *p, LLVMValueRef ptr, Type *type, u switch (kind) { case LLVMStructTypeKind: case LLVMArrayTypeKind: - // NOTE(bill): Enforce zeroing through memset to make sure padding is zeroed too - lb_mem_zero_ptr_internal(p, ptr, lb_const_int(p->module, t_int, sz).value, alignment, false); + if (is_type_tuple(type)) { + // NOTE(bill): even though this should be safe, to keep ASAN happy, do not zero the implicit padding at the end + GB_ASSERT(type->kind == Type_Tuple); + i64 n = type->Tuple.variables.count-1; + i64 end_offset = type->Tuple.offsets[n] + type_size_of(type->Tuple.variables[n]->type); + lb_mem_zero_ptr_internal(p, ptr, lb_const_int(p->module, t_int, end_offset).value, alignment, false); + } else { + // NOTE(bill): Enforce zeroing through memset to make sure padding is zeroed too + lb_mem_zero_ptr_internal(p, ptr, lb_const_int(p->module, t_int, sz).value, alignment, false); + } break; default: LLVMBuildStore(p->builder, LLVMConstNull(lb_type(p->module, type)), ptr);