Skip to content

Commit

Permalink
Merge pull request JuliaLang#38424 from JuliaLang/tb/inttoptr_as
Browse files Browse the repository at this point in the history
Don't create invalid bitcasts.
  • Loading branch information
maleadt committed Nov 18, 2020
2 parents 85000b1 + 40631ed commit c9a149b
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1214,8 +1214,13 @@ static Value *emit_inttoptr(jl_codectx_t &ctx, Value *v, Type *ty)
{
// Almost all of our inttoptr are generated due to representing `Ptr` with `T_size`
// in LLVM and most of these integers are generated from `ptrtoint` in the first place.
if (auto I = dyn_cast<PtrToIntInst>(v))
return ctx.builder.CreateBitCast(I->getOperand(0), ty);
if (auto I = dyn_cast<PtrToIntInst>(v)) {
auto ptr = I->getOperand(0);
if (ty->getPointerAddressSpace() == ptr->getType()->getPointerAddressSpace())
return ctx.builder.CreateBitCast(ptr, ty);
else if (ty->getPointerElementType() == ptr->getType()->getPointerElementType())
return ctx.builder.CreateAddrSpaceCast(ptr, ty);
}
return ctx.builder.CreateIntToPtr(v, ty);
}

Expand Down

0 comments on commit c9a149b

Please sign in to comment.