diff options
| author | LemonBoy <thatlemon@gmail.com> | 2020-10-13 19:34:20 +0200 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2020-10-14 00:05:50 -0400 |
| commit | 0570df69b178c99f4d9d679a57d966f507dda484 (patch) | |
| tree | 7114064614b422868b1fa73f78d7b74c6b27a33d /src | |
| parent | ea45ee54843b10a433bb223caa9706d8253e3222 (diff) | |
| download | zig-0570df69b178c99f4d9d679a57d966f507dda484.tar.gz zig-0570df69b178c99f4d9d679a57d966f507dda484.zip | |
stage1: Fix missing runtime safety check for intToPtr
Elide the alignment check if the pointer alignment is one, the null
check must be preserved as it depends on the pointer type.
Fixes #6667
Diffstat (limited to 'src')
| -rw-r--r-- | src/stage1/codegen.cpp | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/stage1/codegen.cpp b/src/stage1/codegen.cpp index 9ed2ba9d73..5e9b84d25a 100644 --- a/src/stage1/codegen.cpp +++ b/src/stage1/codegen.cpp @@ -3379,7 +3379,7 @@ static LLVMValueRef ir_render_int_to_ptr(CodeGen *g, IrExecutableGen *executable LLVMValueRef target_val = ir_llvm_value(g, instruction->target); const uint32_t align_bytes = get_ptr_align(g, wanted_type); - if (ir_want_runtime_safety(g, &instruction->base) && align_bytes > 1) { + if (ir_want_runtime_safety(g, &instruction->base)) { ZigType *usize = g->builtin_types.entry_usize; LLVMValueRef zero = LLVMConstNull(usize->llvm_type); @@ -3395,7 +3395,7 @@ static LLVMValueRef ir_render_int_to_ptr(CodeGen *g, IrExecutableGen *executable LLVMPositionBuilderAtEnd(g->builder, ok_block); } - { + if (align_bytes > 1) { LLVMValueRef alignment_minus_1 = LLVMConstInt(usize->llvm_type, align_bytes - 1, false); LLVMValueRef anded_val = LLVMBuildAnd(g->builder, target_val, alignment_minus_1, ""); LLVMValueRef is_ok_bit = LLVMBuildICmp(g->builder, LLVMIntEQ, anded_val, zero, ""); |
