diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2018-09-17 19:41:11 -0400 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2018-09-17 19:41:11 -0400 |
| commit | b16229da1de90295b4d173f1a0ddbca677e8cdf2 (patch) | |
| tree | ab8e9558ba662ab085eb35f3ec7365822db71cc4 /src | |
| parent | 78a9a465a372d25ef6f9a1f6bb1018160b8c94e1 (diff) | |
| download | zig-b16229da1de90295b4d173f1a0ddbca677e8cdf2.tar.gz zig-b16229da1de90295b4d173f1a0ddbca677e8cdf2.zip | |
add compile error for @ptrCast 0 bit type to non-0 bit type
Diffstat (limited to 'src')
| -rw-r--r-- | src/ir.cpp | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/src/ir.cpp b/src/ir.cpp index d073f3296c..0cb09df011 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -11528,7 +11528,13 @@ static bool optional_value_is_null(ConstExprValue *val) { static ZigType *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) { Error err; IrInstruction *op1 = bin_op_instruction->op1->other; + if (type_is_invalid(op1->value.type)) + return ira->codegen->builtin_types.entry_invalid; + IrInstruction *op2 = bin_op_instruction->op2->other; + if (type_is_invalid(op2->value.type)) + return ira->codegen->builtin_types.entry_invalid; + AstNode *source_node = bin_op_instruction->base.source_node; IrBinOp op_id = bin_op_instruction->op_id; @@ -20190,11 +20196,19 @@ static ZigType *ir_analyze_instruction_ptr_cast(IrAnalyze *ira, IrInstructionPtr instruction->base.source_node, nullptr, ptr); casted_ptr->value.type = dest_type; - // Keep the bigger alignment, it can only help- - // unless the target is zero bits. - if ((err = type_resolve(ira->codegen, dest_type, ResolveStatusZeroBitsKnown))) + if (type_has_bits(dest_type) && !type_has_bits(src_type)) { + ErrorMsg *msg = ir_add_error(ira, &instruction->base, + buf_sprintf("'%s' and '%s' do not have the same in-memory representation", + buf_ptr(&src_type->name), buf_ptr(&dest_type->name))); + add_error_note(ira->codegen, msg, ptr->source_node, + buf_sprintf("'%s' has no in-memory bits", buf_ptr(&src_type->name))); + add_error_note(ira->codegen, msg, dest_type_value->source_node, + buf_sprintf("'%s' has in-memory bits", buf_ptr(&dest_type->name))); return ira->codegen->builtin_types.entry_invalid; + } + // Keep the bigger alignment, it can only help- + // unless the target is zero bits. IrInstruction *result; if (src_align_bytes > dest_align_bytes && type_has_bits(dest_type)) { result = ir_align_cast(ira, casted_ptr, src_align_bytes, false); |
