aboutsummaryrefslogtreecommitdiff
path: root/src/ir.cpp
diff options
context:
space:
mode:
authorLemonBoy <thatlemon@gmail.com>2020-03-30 13:27:19 +0200
committerAndrew Kelley <andrew@ziglang.org>2020-03-30 11:03:56 -0400
commitc1cc1ebc35f7a56669db2f88b6d4ff8f1603ec59 (patch)
tree17e1064c3d862df1bed5ea4f2e73d789afb1893f /src/ir.cpp
parent8cad45349510b2995a49fc907bdc3c8bf86aa21b (diff)
downloadzig-c1cc1ebc35f7a56669db2f88b6d4ff8f1603ec59.tar.gz
zig-c1cc1ebc35f7a56669db2f88b6d4ff8f1603ec59.zip
ir: Avoid constant-folding ptr to sentinels
Constant-folding the pointers to the expected sentinel value have some big problems: it hides the real content of the array, makes the pointer to the sentinel point to a completely different memory region and treats it like a const value even when the underlying array is mutable. Fixes #4840
Diffstat (limited to 'src/ir.cpp')
-rw-r--r--src/ir.cpp9
1 files changed, 2 insertions, 7 deletions
diff --git a/src/ir.cpp b/src/ir.cpp
index 4d5cfccabe..3a5c9737ee 100644
--- a/src/ir.cpp
+++ b/src/ir.cpp
@@ -20880,13 +20880,8 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP
if (instr_is_comptime(casted_elem_index)) {
uint64_t index = bigint_as_u64(&casted_elem_index->value->data.x_bigint);
if (array_type->id == ZigTypeIdArray) {
- uint64_t array_len = array_type->data.array.len;
- if (index == array_len && array_type->data.array.sentinel != nullptr) {
- ZigType *elem_type = array_type->data.array.child_type;
- IrInstGen *sentinel_elem = ir_const(ira, &elem_ptr_instruction->base.base, elem_type);
- copy_const_val(ira->codegen, sentinel_elem->value, array_type->data.array.sentinel);
- return ir_get_ref(ira, &elem_ptr_instruction->base.base, sentinel_elem, true, false);
- }
+ uint64_t array_len = array_type->data.array.len +
+ (array_type->data.array.sentinel != nullptr);
if (index >= array_len) {
ir_add_error_node(ira, elem_ptr_instruction->base.base.source_node,
buf_sprintf("index %" ZIG_PRI_u64 " outside array of size %" ZIG_PRI_u64,