aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2020-08-07 11:50:15 -0700
committerAndrew Kelley <andrew@ziglang.org>2020-08-07 23:36:36 -0400
commitab483281d31c852e77fe0afc6a623fedd1574546 (patch)
tree0bd35f022784035d8ca3574d4d06b113e528bc5a /src
parent2fc18b52788f789ceba7b4f60e850de3ce67495c (diff)
downloadzig-ab483281d31c852e77fe0afc6a623fedd1574546.tar.gz
zig-ab483281d31c852e77fe0afc6a623fedd1574546.zip
stage1: elide `@intToPtr` alignment safety check for 1-byte alignment
Diffstat (limited to 'src')
-rw-r--r--src/codegen.cpp4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/codegen.cpp b/src/codegen.cpp
index 3f3d80d51d..023c94f245 100644
--- a/src/codegen.cpp
+++ b/src/codegen.cpp
@@ -3480,8 +3480,9 @@ static LLVMValueRef ir_render_widen_or_shorten(CodeGen *g, IrExecutableGen *exec
static LLVMValueRef ir_render_int_to_ptr(CodeGen *g, IrExecutableGen *executable, IrInstGenIntToPtr *instruction) {
ZigType *wanted_type = instruction->base.value->type;
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)) {
+ if (ir_want_runtime_safety(g, &instruction->base) && align_bytes > 1) {
ZigType *usize = g->builtin_types.entry_usize;
LLVMValueRef zero = LLVMConstNull(usize->llvm_type);
@@ -3498,7 +3499,6 @@ static LLVMValueRef ir_render_int_to_ptr(CodeGen *g, IrExecutableGen *executable
}
{
- const uint32_t align_bytes = get_ptr_align(g, wanted_type);
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, "");