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 10, 2018
1 parent 51f42f1 commit 1381f0c
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 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,12 +310,8 @@ 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);
unboxed = ctx.builder.CreateBitCast(unboxed, to);
}
return unboxed;
}
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 1381f0c

Please sign in to comment.