aboutsummaryrefslogtreecommitdiff
path: root/src/ir.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2019-03-25 21:00:45 +0000
committergingerBill <bill@gingerbill.org>2019-03-25 21:00:45 +0000
commit4a156897764d3030a10ee5e3ce4b08e0e090365e (patch)
treefa05c91381af544be9109247a6401fb272c88b94 /src/ir.cpp
parentc785c3569f1e4b6a26c1c215c3f9deb112800a63 (diff)
Remove bounds checks for slice expressions with both indices empty
Diffstat (limited to 'src/ir.cpp')
-rw-r--r--src/ir.cpp16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/ir.cpp b/src/ir.cpp
index 6631711b5..bfc4fae82 100644
--- a/src/ir.cpp
+++ b/src/ir.cpp
@@ -7186,7 +7186,9 @@ irAddr ir_build_addr(irProcedure *proc, Ast *expr) {
irValue *len = ir_slice_len(proc, base);
if (high == nullptr) high = len;
- ir_emit_slice_bounds_check(proc, se->open, low, high, len, false);
+ if (se->low != nullptr || se->high != nullptr) {
+ ir_emit_slice_bounds_check(proc, se->open, low, high, len, false);
+ }
irValue *elem = ir_emit_ptr_offset(proc, ir_slice_elem(proc, base), low);
irValue *new_len = ir_emit_arith(proc, Token_Sub, high, low, t_int);
@@ -7203,7 +7205,9 @@ irAddr ir_build_addr(irProcedure *proc, Ast *expr) {
irValue *len = ir_dynamic_array_len(proc, base);
if (high == nullptr) high = len;
- ir_emit_slice_bounds_check(proc, se->open, low, high, len, false);
+ if (se->low != nullptr || se->high != nullptr) {
+ ir_emit_slice_bounds_check(proc, se->open, low, high, len, false);
+ }
irValue *elem = ir_emit_ptr_offset(proc, ir_dynamic_array_elem(proc, base), low);
irValue *new_len = ir_emit_arith(proc, Token_Sub, high, low, t_int);
@@ -7224,7 +7228,9 @@ irAddr ir_build_addr(irProcedure *proc, Ast *expr) {
bool high_const = type_and_value_of_expr(se->high).mode == Addressing_Constant;
if (!low_const || !high_const) {
- ir_emit_slice_bounds_check(proc, se->open, low, high, len, false);
+ if (se->low != nullptr || se->high != nullptr) {
+ ir_emit_slice_bounds_check(proc, se->open, low, high, len, false);
+ }
}
irValue *elem = ir_emit_ptr_offset(proc, ir_array_elem(proc, addr), low);
irValue *new_len = ir_emit_arith(proc, Token_Sub, high, low, t_int);
@@ -7240,7 +7246,9 @@ irAddr ir_build_addr(irProcedure *proc, Ast *expr) {
if (high == nullptr) high = len;
// if (max == nullptr) max = ir_string_len(proc, base);
- ir_emit_slice_bounds_check(proc, se->open, low, high, len, true);
+ if (se->low != nullptr || se->high != nullptr) {
+ ir_emit_slice_bounds_check(proc, se->open, low, high, len, true);
+ }
irValue *elem = ir_emit_ptr_offset(proc, ir_string_elem(proc, base), low);
irValue *new_len = ir_emit_arith(proc, Token_Sub, high, low, t_int);