Skip to content

Commit 1381f0c

Browse files
committed
codegen: tolerate type mismatches in dead code
1 parent 51f42f1 commit 1381f0c

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

src/intrinsics.cpp

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -279,9 +279,22 @@ static jl_cgval_t ghostValue(jl_value_t *ty);
279279
static Value *emit_unboxed_coercion(jl_codectx_t &ctx, Type *to, Value *unboxed)
280280
{
281281
Type *ty = unboxed->getType();
282-
assert(ty != T_void);
283282
bool frompointer = ty->isPointerTy();
284283
bool topointer = to->isPointerTy();
284+
#if JL_LLVM_VERSION >= 40000
285+
const DataLayout &DL = jl_data_layout;
286+
#else
287+
const DataLayout &DL = jl_ExecutionEngine->getDataLayout();
288+
#endif
289+
if (ty == T_int1 && to == T_int8) {
290+
// bools may be stored internally as int8
291+
unboxed = ctx.builder.CreateZExt(unboxed, T_int8);
292+
}
293+
else if (ty == T_void || DL.getTypeSizeInBits(ty) != DL.getTypeSizeInBits(to)) {
294+
// this can happen in dead code
295+
//emit_unreachable(ctx);
296+
return UndefValue::get(to);
297+
}
285298
if (frompointer && topointer) {
286299
unboxed = emit_bitcast(ctx, unboxed, to);
287300
}
@@ -297,12 +310,8 @@ static Value *emit_unboxed_coercion(jl_codectx_t &ctx, Type *to, Value *unboxed)
297310
unboxed = ctx.builder.CreateBitCast(unboxed, INTT_to);
298311
unboxed = ctx.builder.CreateIntToPtr(unboxed, to);
299312
}
300-
else if (ty == T_int1 && to == T_int8) {
301-
// bools may be stored internally as int8
302-
unboxed = ctx.builder.CreateZExt(unboxed, T_int8);
303-
}
304313
else if (ty != to) {
305-
unboxed = ctx.builder.CreateBitCast(unboxed, to);
314+
unboxed = ctx.builder.CreateBitCast(unboxed, to);
306315
}
307316
return unboxed;
308317
}
@@ -319,7 +328,7 @@ static Value *emit_unbox(jl_codectx_t &ctx, Type *to, const jl_cgval_t &x, jl_va
319328
if (type_is_ghost(to)) {
320329
return NULL;
321330
}
322-
//emit_error(ctx, "emit_unbox: a type mismatch error in occurred during codegen");
331+
//emit_unreachable(ctx);
323332
return UndefValue::get(to); // type mismatch error
324333
}
325334

0 commit comments

Comments
 (0)