aboutsummaryrefslogtreecommitdiff
path: root/src/analyze.cpp
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2017-02-26 23:50:04 -0500
committerAndrew Kelley <superjoe30@gmail.com>2017-02-26 23:50:04 -0500
commit25761570f1bb4413020ebbfc959caa3429453517 (patch)
treeac228c95e0393a8b36202864c60a4fd712a0e8d3 /src/analyze.cpp
parent8dd0b4e1f12bc9f70ff6c312b35563595fdb4476 (diff)
downloadzig-25761570f1bb4413020ebbfc959caa3429453517.tar.gz
zig-25761570f1bb4413020ebbfc959caa3429453517.zip
more robust const struct values
Diffstat (limited to 'src/analyze.cpp')
-rw-r--r--src/analyze.cpp26
1 files changed, 22 insertions, 4 deletions
diff --git a/src/analyze.cpp b/src/analyze.cpp
index 842ddbdf48..03da4a26c7 100644
--- a/src/analyze.cpp
+++ b/src/analyze.cpp
@@ -3485,10 +3485,11 @@ void init_const_undefined(CodeGen *g, ConstExprValue *const_val) {
ConstExprValue *element_val = &const_val->data.x_array.elements[i];
element_val->type = canon_wanted_type->data.array.child_type;
init_const_undefined(g, element_val);
- if (get_underlying_type(element_val->type)->id == TypeTableEntryIdArray) {
- element_val->data.x_array.parent.id = ConstParentIdArray;
- element_val->data.x_array.parent.data.p_array.array_val = const_val;
- element_val->data.x_array.parent.data.p_array.elem_index = i;
+ ConstParent *parent = get_const_val_parent(element_val);
+ if (parent != nullptr) {
+ parent->id = ConstParentIdArray;
+ parent->data.p_array.array_val = const_val;
+ parent->data.p_array.elem_index = i;
}
}
} else if (canon_wanted_type->id == TypeTableEntryIdStruct) {
@@ -3502,6 +3503,12 @@ void init_const_undefined(CodeGen *g, ConstExprValue *const_val) {
field_val->type = canon_wanted_type->data.structure.fields[i].type_entry;
assert(field_val->type);
init_const_undefined(g, field_val);
+ ConstParent *parent = get_const_val_parent(field_val);
+ if (parent != nullptr) {
+ parent->id = ConstParentIdStruct;
+ parent->data.p_struct.struct_val = const_val;
+ parent->data.p_struct.field_index = i;
+ }
}
} else {
const_val->special = ConstValSpecialUndef;
@@ -4068,3 +4075,14 @@ bool zig_llvm_fn_key_eql(ZigLLVMFnKey a, ZigLLVMFnKey b) {
}
zig_unreachable();
}
+
+ConstParent *get_const_val_parent(ConstExprValue *value) {
+ assert(value->type);
+ TypeTableEntry *canon_type = get_underlying_type(value->type);
+ if (canon_type->id == TypeTableEntryIdArray) {
+ return &value->data.x_array.parent;
+ } else if (canon_type->id == TypeTableEntryIdStruct) {
+ return &value->data.x_struct.parent;
+ }
+ return nullptr;
+}