@@ -279,9 +279,22 @@ static jl_cgval_t ghostValue(jl_value_t *ty);
279
279
static Value *emit_unboxed_coercion (jl_codectx_t &ctx, Type *to, Value *unboxed)
280
280
{
281
281
Type *ty = unboxed->getType ();
282
- assert (ty != T_void);
283
282
bool frompointer = ty->isPointerTy ();
284
283
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
+ }
285
298
if (frompointer && topointer) {
286
299
unboxed = emit_bitcast (ctx, unboxed, to);
287
300
}
@@ -297,12 +310,8 @@ static Value *emit_unboxed_coercion(jl_codectx_t &ctx, Type *to, Value *unboxed)
297
310
unboxed = ctx.builder .CreateBitCast (unboxed, INTT_to);
298
311
unboxed = ctx.builder .CreateIntToPtr (unboxed, to);
299
312
}
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
- }
304
313
else if (ty != to) {
305
- unboxed = ctx.builder .CreateBitCast (unboxed, to);
314
+ unboxed = ctx.builder .CreateBitCast (unboxed, to);
306
315
}
307
316
return unboxed;
308
317
}
@@ -319,7 +328,7 @@ static Value *emit_unbox(jl_codectx_t &ctx, Type *to, const jl_cgval_t &x, jl_va
319
328
if (type_is_ghost (to)) {
320
329
return NULL ;
321
330
}
322
- // emit_error (ctx, "emit_unbox: a type mismatch error in occurred during codegen" );
331
+ // emit_unreachable (ctx);
323
332
return UndefValue::get (to); // type mismatch error
324
333
}
325
334
0 commit comments