aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLemonBoy <thatlemon@gmail.com>2019-11-04 15:09:11 +0100
committerLemonBoy <thatlemon@gmail.com>2019-11-04 20:33:41 +0100
commitc47211cc60a826837191fbb87b32f0baacb167cb (patch)
treea57056e838fabfb5ac51cffed26bee084402affa /src
parent2b4bf1e7ced151482ce741788eadcb39f6d60f72 (diff)
downloadzig-c47211cc60a826837191fbb87b32f0baacb167cb.tar.gz
zig-c47211cc60a826837191fbb87b32f0baacb167cb.zip
Prevent crash when slicing undefined ptr to slice
Fixes #3534
Diffstat (limited to 'src')
-rw-r--r--src/ir.cpp18
1 files changed, 13 insertions, 5 deletions
diff --git a/src/ir.cpp b/src/ir.cpp
index ea87999454..211af9a758 100644
--- a/src/ir.cpp
+++ b/src/ir.cpp
@@ -22949,12 +22949,20 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction
if (parent_ptr == nullptr)
return ira->codegen->invalid_instruction;
- array_val = const_ptr_pointee(ira, ira->codegen, parent_ptr, instruction->base.source_node);
- if (array_val == nullptr)
- return ira->codegen->invalid_instruction;
- rel_end = child_array_type->data.array.len;
- abs_offset = 0;
+ if (parent_ptr->special == ConstValSpecialUndef) {
+ array_val = nullptr;
+ abs_offset = 0;
+ rel_end = SIZE_MAX;
+ ptr_is_undef = true;
+ } else {
+ array_val = const_ptr_pointee(ira, ira->codegen, parent_ptr, instruction->base.source_node);
+ if (array_val == nullptr)
+ return ira->codegen->invalid_instruction;
+
+ rel_end = child_array_type->data.array.len;
+ abs_offset = 0;
+ }
} else {
array_val = const_ptr_pointee(ira, ira->codegen, &ptr_ptr->value, instruction->base.source_node);
if (array_val == nullptr)