aboutsummaryrefslogtreecommitdiff
path: root/src/llvm_backend.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2021-03-30 20:38:04 +0100
committergingerBill <bill@gingerbill.org>2021-03-30 20:38:04 +0100
commit3359d0323a3115601b49ac7d6860c8b15babb491 (patch)
tree7543035a8949c5762f292b601b8a4f0a4fd15d89 /src/llvm_backend.cpp
parentfbd01660ee8cff6d17e54e9e4b6ffd4e5011083b (diff)
Change `>>` behaviour in LLVM to prevent stupid UB
Diffstat (limited to 'src/llvm_backend.cpp')
-rw-r--r--src/llvm_backend.cpp8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/llvm_backend.cpp b/src/llvm_backend.cpp
index 92b180f73..e8028eece 100644
--- a/src/llvm_backend.cpp
+++ b/src/llvm_backend.cpp
@@ -6600,7 +6600,6 @@ handle_op:
LLVMValueRef bits = rhs.value;
LLVMValueRef bit_size = LLVMConstInt(lb_type(p->module, rhs.type), 8*type_size_of(lhs.type), false);
- LLVMValueRef max = LLVMConstInt(lb_type(p->module, rhs.type), 8*type_size_of(lhs.type)-1, false);
LLVMValueRef width_test = LLVMBuildICmp(p->builder, LLVMIntULT, bits, bit_size, "");
@@ -6617,16 +6616,17 @@ handle_op:
bool is_unsigned = is_type_unsigned(type);
LLVMValueRef bit_size = LLVMConstInt(lb_type(p->module, rhs.type), 8*type_size_of(lhs.type), false);
- LLVMValueRef max = LLVMConstInt(lb_type(p->module, rhs.type), 8*type_size_of(lhs.type)-1, false);
LLVMValueRef width_test = LLVMBuildICmp(p->builder, LLVMIntULT, bits, bit_size, "");
- bits = LLVMBuildSelect(p->builder, width_test, bits, max, "");
if (is_unsigned) {
- res.value = LLVMBuildLShr(p->builder, lhs.value, bits, "");
+ res.value = LLVMBuildLShr(p->builder, lhsval, bits, "");
} else {
res.value = LLVMBuildAShr(p->builder, lhsval, bits, "");
}
+
+ LLVMValueRef zero = LLVMConstNull(lb_type(p->module, lhs.type));
+ res.value = LLVMBuildSelect(p->builder, width_test, res.value, zero, "");
return res;
}
case Token_AndNot: