aboutsummaryrefslogtreecommitdiff
path: root/src/ir.cpp
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2017-04-06 05:34:04 -0400
committerAndrew Kelley <superjoe30@gmail.com>2017-04-06 05:34:04 -0400
commit6fbe1632d0c958b9abbc9f38a7e497ef69543bf1 (patch)
treec5ee08ab23927e79a2827beebeb5e879e6596f7c /src/ir.cpp
parentd15bcdce691c1f42f70a5e9943817eb5ba974893 (diff)
downloadzig-6fbe1632d0c958b9abbc9f38a7e497ef69543bf1.tar.gz
zig-6fbe1632d0c958b9abbc9f38a7e497ef69543bf1.zip
Update zig build system to support user defined options
* Fix assertion failure when switching on type. Closes #310 * Update zig build system to support user defined options. See #204 * fmt.format supports {sNNN} to set padding for a buffer arg. * add std.fmt.bufPrint and std.fmt.allocPrint * std.hash_map.HashMap.put returns the previous value * add std.mem.startsWith
Diffstat (limited to 'src/ir.cpp')
-rw-r--r--src/ir.cpp14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/ir.cpp b/src/ir.cpp
index 1fb839ea9d..a1ccce7f2c 100644
--- a/src/ir.cpp
+++ b/src/ir.cpp
@@ -57,6 +57,7 @@ static TypeTableEntry *ir_analyze_instruction(IrAnalyze *ira, IrInstruction *ins
static IrInstruction *ir_implicit_cast(IrAnalyze *ira, IrInstruction *value, TypeTableEntry *expected_type);
ConstExprValue *const_ptr_pointee(ConstExprValue *const_val) {
+ assert(const_val->type->id == TypeTableEntryIdPointer);
assert(const_val->special == ConstValSpecialStatic);
switch (const_val->data.x_ptr.special) {
case ConstPtrSpecialInvalid:
@@ -10350,10 +10351,21 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira,
if (type_is_invalid(target_value_ptr->value.type))
return ira->codegen->builtin_types.entry_invalid;
+ if (target_value_ptr->value.type->id == TypeTableEntryIdMetaType) {
+ assert(instr_is_comptime(target_value_ptr));
+ TypeTableEntry *ptr_type = target_value_ptr->value.data.x_type;
+ assert(ptr_type->id == TypeTableEntryIdPointer);
+ ConstExprValue *out_val = ir_build_const_from(ira, &switch_target_instruction->base);
+ out_val->type = ira->codegen->builtin_types.entry_type;
+ out_val->data.x_type = ptr_type->data.pointer.child_type;
+ return out_val->type;
+ }
+
assert(target_value_ptr->value.type->id == TypeTableEntryIdPointer);
+
TypeTableEntry *target_type = target_value_ptr->value.type->data.pointer.child_type;
ConstExprValue *pointee_val = nullptr;
- if (target_value_ptr->value.special != ConstValSpecialRuntime) {
+ if (instr_is_comptime(target_value_ptr)) {
pointee_val = const_ptr_pointee(&target_value_ptr->value);
if (pointee_val->special == ConstValSpecialRuntime)
pointee_val = nullptr;