diff options
| author | gingerBill <bill@gingerbill.org> | 2021-05-03 15:57:35 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2021-05-03 15:57:35 +0100 |
| commit | e4286d0ff9d383d03b220ac8fc52934853b35c34 (patch) | |
| tree | df49c45a57dc1b2e02a3067cc2dfb0a08e603bd2 /src/llvm_backend.cpp | |
| parent | 3a556eb3046f3f7ff1183981b261ac38e38c0c87 (diff) | |
Force `zero_init` in `lb_add_local` in certain cases
Diffstat (limited to 'src/llvm_backend.cpp')
| -rw-r--r-- | src/llvm_backend.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/llvm_backend.cpp b/src/llvm_backend.cpp index 72694e562..2c61132dd 100644 --- a/src/llvm_backend.cpp +++ b/src/llvm_backend.cpp @@ -3424,6 +3424,21 @@ lbAddr lb_add_local(lbProcedure *p, Type *type, Entity *e, bool zero_init, i32 p LLVMSetAlignment(ptr, alignment); LLVMPositionBuilderAtEnd(p->builder, p->curr_block->block); + + + if (!zero_init) { + // If there is any padding of any kind, just zero init regardless of zero_init parameter + LLVMTypeKind kind = LLVMGetTypeKind(llvm_type); + if (kind == LLVMStructTypeKind) { + i64 sz = type_size_of(type); + if (type_size_of_struct_pretend_is_packed(type) != sz) { + zero_init = true; + } + } else if (kind == LLVMArrayTypeKind) { + zero_init = true; + } + } + if (zero_init) { LLVMTypeKind kind = LLVMGetTypeKind(llvm_type); |