aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2019-06-19 18:47:02 -0400
committerAndrew Kelley <andrew@ziglang.org>2019-06-19 18:47:02 -0400
commit4ffab5b85f03f63a7e724698482f8497cacc7212 (patch)
tree0928e6e3573faf78e3b11e53f16affd183cc92a3 /src
parentc7dc03fcb16abfac2d914002a609b8144f7cdab2 (diff)
downloadzig-4ffab5b85f03f63a7e724698482f8497cacc7212.tar.gz
zig-4ffab5b85f03f63a7e724698482f8497cacc7212.zip
fix optional pointer to size zero struct
Diffstat (limited to 'src')
-rw-r--r--src/codegen.cpp15
-rw-r--r--src/ir.cpp15
2 files changed, 22 insertions, 8 deletions
diff --git a/src/codegen.cpp b/src/codegen.cpp
index 05bdf92555..b55b8a1094 100644
--- a/src/codegen.cpp
+++ b/src/codegen.cpp
@@ -4983,7 +4983,7 @@ static LLVMValueRef ir_render_unwrap_err_payload(CodeGen *g, IrExecutable *execu
}
}
-static LLVMValueRef ir_render_maybe_wrap(CodeGen *g, IrExecutable *executable, IrInstructionOptionalWrap *instruction) {
+static LLVMValueRef ir_render_optional_wrap(CodeGen *g, IrExecutable *executable, IrInstructionOptionalWrap *instruction) {
ZigType *wanted_type = instruction->base.value.type;
assert(wanted_type->id == ZigTypeIdOptional);
@@ -4991,11 +4991,20 @@ static LLVMValueRef ir_render_maybe_wrap(CodeGen *g, IrExecutable *executable, I
ZigType *child_type = wanted_type->data.maybe.child_type;
if (!type_has_bits(child_type)) {
- return LLVMConstInt(LLVMInt1Type(), 1, false);
+ LLVMValueRef result = LLVMConstAllOnes(LLVMInt1Type());
+ if (instruction->result_loc != nullptr) {
+ LLVMValueRef result_loc = ir_llvm_value(g, instruction->result_loc);
+ gen_store_untyped(g, result, result_loc, 0, false);
+ }
+ return result;
}
LLVMValueRef payload_val = ir_llvm_value(g, instruction->operand);
if (!handle_is_ptr(wanted_type)) {
+ if (instruction->result_loc != nullptr) {
+ LLVMValueRef result_loc = ir_llvm_value(g, instruction->result_loc);
+ gen_store_untyped(g, payload_val, result_loc, 0, false);
+ }
return payload_val;
}
@@ -5666,7 +5675,7 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable,
case IrInstructionIdUnwrapErrPayload:
return ir_render_unwrap_err_payload(g, executable, (IrInstructionUnwrapErrPayload *)instruction);
case IrInstructionIdOptionalWrap:
- return ir_render_maybe_wrap(g, executable, (IrInstructionOptionalWrap *)instruction);
+ return ir_render_optional_wrap(g, executable, (IrInstructionOptionalWrap *)instruction);
case IrInstructionIdErrWrapCode:
return ir_render_err_wrap_code(g, executable, (IrInstructionErrWrapCode *)instruction);
case IrInstructionIdErrWrapPayload:
diff --git a/src/ir.cpp b/src/ir.cpp
index 356a1a8cc8..0a920c0974 100644
--- a/src/ir.cpp
+++ b/src/ir.cpp
@@ -1826,7 +1826,7 @@ static IrInstruction *ir_build_optional_wrap(IrAnalyze *ira, IrInstruction *sour
instruction->result_loc = result_loc;
ir_ref_instruction(operand, ira->new_irb.current_basic_block);
- ir_ref_instruction(result_loc, ira->new_irb.current_basic_block);
+ if (result_loc != nullptr) ir_ref_instruction(result_loc, ira->new_irb.current_basic_block);
return &instruction->base;
}
@@ -11277,10 +11277,15 @@ static IrInstruction *ir_analyze_optional_wrap(IrAnalyze *ira, IrInstruction *so
return &const_instruction->base;
}
- if (result_loc == nullptr) result_loc = no_result_loc();
- IrInstruction *result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true);
- if (type_is_invalid(result_loc_inst->value.type) || instr_is_unreachable(result_loc_inst)) {
- return result_loc_inst;
+ if (result_loc == nullptr && handle_is_ptr(wanted_type)) {
+ result_loc = no_result_loc();
+ }
+ IrInstruction *result_loc_inst = nullptr;
+ if (result_loc != nullptr) {
+ result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true);
+ if (type_is_invalid(result_loc_inst->value.type) || instr_is_unreachable(result_loc_inst)) {
+ return result_loc_inst;
+ }
}
IrInstruction *result = ir_build_optional_wrap(ira, source_instr, wanted_type, value, result_loc_inst);
result->value.data.rh_maybe = RuntimeHintOptionalNonNull;