Skip to content

Commit

Permalink
codegen: tolerate type mismatches in dead code
Browse files Browse the repository at this point in the history
  • Loading branch information
vtjnash committed Jan 19, 2018
1 parent 6147df6 commit 32ce590
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/intrinsics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,22 @@ static jl_cgval_t ghostValue(jl_value_t *ty);
static Value *emit_unboxed_coercion(jl_codectx_t &ctx, Type *to, Value *unboxed)
{
Type *ty = unboxed->getType();
assert(ty != T_void);
bool frompointer = ty->isPointerTy();
bool topointer = to->isPointerTy();
#if JL_LLVM_VERSION >= 40000
const DataLayout &DL = jl_data_layout;
#else
const DataLayout &DL = jl_ExecutionEngine->getDataLayout();
#endif
if (ty == T_int1 && to == T_int8) {
// bools may be stored internally as int8
unboxed = ctx.builder.CreateZExt(unboxed, T_int8);
}
else if (ty == T_void || DL.getTypeSizeInBits(ty) != DL.getTypeSizeInBits(to)) {
// this can happen in dead code
//emit_unreachable(ctx);
return UndefValue::get(to);
}
if (frompointer && topointer) {
unboxed = emit_bitcast(ctx, unboxed, to);
}
Expand All @@ -297,10 +310,6 @@ static Value *emit_unboxed_coercion(jl_codectx_t &ctx, Type *to, Value *unboxed)
unboxed = ctx.builder.CreateBitCast(unboxed, INTT_to);
unboxed = ctx.builder.CreateIntToPtr(unboxed, to);
}
else if (ty == T_int1 && to == T_int8) {
// bools may be stored internally as int8
unboxed = ctx.builder.CreateZExt(unboxed, T_int8);
}
else if (ty != to) {
unboxed = ctx.builder.CreateBitCast(unboxed, to);
}
Expand All @@ -319,7 +328,7 @@ static Value *emit_unbox(jl_codectx_t &ctx, Type *to, const jl_cgval_t &x, jl_va
if (type_is_ghost(to)) {
return NULL;
}
//emit_error(ctx, "emit_unbox: a type mismatch error in occurred during codegen");
//emit_unreachable(ctx);
return UndefValue::get(to); // type mismatch error
}

Expand Down

0 comments on commit 32ce590

Please sign in to comment.