aboutsummaryrefslogtreecommitdiff
path: root/src/codegen.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/codegen.cpp')
-rw-r--r--src/codegen.cpp20
1 files changed, 19 insertions, 1 deletions
diff --git a/src/codegen.cpp b/src/codegen.cpp
index b86f3b3b5a..6d26793013 100644
--- a/src/codegen.cpp
+++ b/src/codegen.cpp
@@ -833,6 +833,24 @@ static LLVMValueRef gen_prefix_op_expr(CodeGen *g, AstNode *node) {
{
zig_panic("TODO codegen PrefixOpError");
}
+ case PrefixOpUnwrapError:
+ {
+ LLVMValueRef expr_val = gen_expr(g, expr_node);
+ TypeTableEntry *expr_type = get_expr_type(expr_node);
+ assert(expr_type->id == TypeTableEntryIdErrorUnion);
+ TypeTableEntry *child_type = expr_type->data.error.child_type;
+ // TODO in debug mode, put a panic here if the error is not 0
+ if (child_type->size_in_bits > 0) {
+ LLVMValueRef child_val_ptr = LLVMBuildStructGEP(g->builder, expr_val, 1, "");
+ if (handle_is_ptr(child_type)) {
+ return child_val_ptr;
+ } else {
+ return expr_val;
+ }
+ } else {
+ return nullptr;
+ }
+ }
}
zig_unreachable();
}
@@ -2219,7 +2237,7 @@ static LLVMValueRef gen_const_val(CodeGen *g, TypeTableEntry *type_entry, ConstE
assert(const_val->ok);
if (const_val->undef) {
- return LLVMConstNull(type_entry->type_ref);
+ return LLVMGetUndef(type_entry->type_ref);
}
if (type_entry->id == TypeTableEntryIdInt) {