aboutsummaryrefslogtreecommitdiff
path: root/src/analyze.cpp
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2019-01-09 10:44:57 -0500
committerAndrew Kelley <andrew@ziglang.org>2019-01-09 10:44:57 -0500
commit3b2eeb839bb34903596edeae041b5d9ab189282d (patch)
tree05c4b419771e26ed502e282d2ad4594e52f938cb /src/analyze.cpp
parent027a0c46aef9828ab07d6342030c1ba5b5e4f769 (diff)
parent5864d92b4049e6d60a21a3f22220464808dd0518 (diff)
downloadzig-3b2eeb839bb34903596edeae041b5d9ab189282d.tar.gz
zig-3b2eeb839bb34903596edeae041b5d9ab189282d.zip
Merge remote-tracking branch 'origin/master' into llvm8
Diffstat (limited to 'src/analyze.cpp')
-rw-r--r--src/analyze.cpp21
1 files changed, 19 insertions, 2 deletions
diff --git a/src/analyze.cpp b/src/analyze.cpp
index af65838eae..00eb38de9e 100644
--- a/src/analyze.cpp
+++ b/src/analyze.cpp
@@ -5757,7 +5757,8 @@ void render_const_val_ptr(CodeGen *g, Buf *buf, ConstExprValue *const_val, ZigTy
case ConstPtrSpecialRef:
case ConstPtrSpecialBaseStruct:
buf_appendf(buf, "*");
- render_const_value(g, buf, const_ptr_pointee(g, const_val));
+ // TODO we need a source node for const_ptr_pointee because it can generate compile errors
+ render_const_value(g, buf, const_ptr_pointee(nullptr, g, const_val, nullptr));
return;
case ConstPtrSpecialBaseArray:
if (const_val->data.x_ptr.data.base_array.is_cstr) {
@@ -5765,7 +5766,8 @@ void render_const_val_ptr(CodeGen *g, Buf *buf, ConstExprValue *const_val, ZigTy
return;
} else {
buf_appendf(buf, "*");
- render_const_value(g, buf, const_ptr_pointee(g, const_val));
+ // TODO we need a source node for const_ptr_pointee because it can generate compile errors
+ render_const_value(g, buf, const_ptr_pointee(nullptr, g, const_val, nullptr));
return;
}
case ConstPtrSpecialHardCodedAddr:
@@ -6599,3 +6601,18 @@ uint32_t get_host_int_bytes(CodeGen *g, ZigType *struct_type, TypeStructField *f
LLVMTypeRef field_type = LLVMStructGetTypeAtIndex(struct_type->type_ref, field->gen_index);
return LLVMStoreSizeOfType(g->target_data_ref, field_type);
}
+
+Error ensure_const_val_repr(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node,
+ ConstExprValue *const_val, ZigType *wanted_type)
+{
+ ConstExprValue ptr_val = {};
+ ptr_val.special = ConstValSpecialStatic;
+ ptr_val.type = get_pointer_to_type(codegen, wanted_type, true);
+ ptr_val.data.x_ptr.mut = ConstPtrMutComptimeConst;
+ ptr_val.data.x_ptr.special = ConstPtrSpecialRef;
+ ptr_val.data.x_ptr.data.ref.pointee = const_val;
+ if (const_ptr_pointee(ira, codegen, &ptr_val, source_node) == nullptr)
+ return ErrorSemanticAnalyzeFail;
+
+ return ErrorNone;
+}