aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJimmi HC <jimmiholstchristensen@gmail.com>2019-04-24 15:04:58 +0200
committerJimmi HC <jimmiholstchristensen@gmail.com>2019-04-24 15:04:58 +0200
commit1a2e02e267216bb35937d25598c773255d830b25 (patch)
treee48d37cb4f083692dffb89b57ec75795d374991b /src
parent3bc361178c0f37ee9ffb67698401027a9f656664 (diff)
downloadzig-1a2e02e267216bb35937d25598c773255d830b25.tar.gz
zig-1a2e02e267216bb35937d25598c773255d830b25.zip
fixed #2356
const_ptr_pointee_unchecked did not take into account that if the pointer is zero sized, then const_val->data.x_ptr.special would be ConstPtrSpecialInvalid. This commit fixes this by also checking that the child type of the pointer only have one possible value and just returns that value.
Diffstat (limited to 'src')
-rw-r--r--src/ir.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/ir.cpp b/src/ir.cpp
index a3d08b5327..e5192cf347 100644
--- a/src/ir.cpp
+++ b/src/ir.cpp
@@ -188,6 +188,19 @@ static ConstExprValue *const_ptr_pointee_unchecked(CodeGen *g, ConstExprValue *c
assert(get_src_ptr_type(const_val->type) != nullptr);
assert(const_val->special == ConstValSpecialStatic);
ConstExprValue *result;
+
+ switch (type_has_one_possible_value(g, const_val->type->data.pointer.child_type)) {
+ case OnePossibleValueInvalid:
+ zig_unreachable();
+ case OnePossibleValueYes:
+ result = create_const_vals(1);
+ result->type = const_val->type->data.pointer.child_type;
+ result->special = ConstValSpecialStatic;
+ return result;
+ case OnePossibleValueNo:
+ break;
+ }
+
switch (const_val->data.x_ptr.special) {
case ConstPtrSpecialInvalid:
zig_unreachable();