Skip to content

Commit

Permalink
ensure that constants are treated as values rather than opaque pointers
Browse files Browse the repository at this point in the history
  • Loading branch information
vtjnash committed Feb 16, 2017
1 parent 4504803 commit be88ee9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 22 deletions.
44 changes: 23 additions & 21 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3808,7 +3808,29 @@ static void emit_assignment(jl_value_t *l, jl_value_t *r, jl_codectx_t *ctx)
if (vi.value.V == NULL) {
// all ghost values in destination - nothing to copy or store
}
else if (rval_info.ispointer()) {
else if (rval_info.constant || !rval_info.ispointer()) {
if (rval_info.isghost) {
// all ghost values in source - nothing to copy or store
}
else {
if (rval_info.typ != vi.value.typ && !vi.pTIndex && !rval_info.TIndex) {
// isbits cast-on-assignment is invalid. this branch should be dead-code.
CreateTrap(builder);
}
else {
Value *dest = vi.value.V;
Type *store_ty = julia_type_to_llvm(rval_info.constant ? jl_typeof(rval_info.constant) : rval_info.typ);
Type *dest_ty = store_ty->getPointerTo();
if (dest_ty != dest->getType())
dest = emit_bitcast(dest, dest_ty);
tbaa_decorate(tbaa_stack, builder.CreateStore(
emit_unbox(store_ty, rval_info, rval_info.typ),
dest,
vi.isVolatile));
}
}
}
else {
MDNode *tbaa = rval_info.tbaa;
// the memcpy intrinsic does not allow to specify different alias tags
// for the load part (x.tbaa) and the store part (tbaa_stack).
Expand All @@ -3833,26 +3855,6 @@ static void emit_assignment(jl_value_t *l, jl_value_t *r, jl_codectx_t *ctx)
vi.isVolatile,
tbaa);
}
else if (rval_info.V == NULL) {
// all ghost values in source - nothing to copy or store
}
else {
if (rval_info.typ != vi.value.typ && !vi.pTIndex && !rval_info.TIndex) {
// isbits cast-on-assignment is invalid. this branch should be dead-code.
CreateTrap(builder);
}
else {
Value *dest = vi.value.V;
Type *store_ty = julia_type_to_llvm(rval_info.typ);
Type *dest_ty = store_ty->getPointerTo();
if (dest_ty != dest->getType())
dest = emit_bitcast(dest, dest_ty);
tbaa_decorate(tbaa_stack, builder.CreateStore(
emit_unbox(store_ty, rval_info, rval_info.typ),
dest,
vi.isVolatile));
}
}
}
else {
assert(vi.pTIndex == NULL);
Expand Down
2 changes: 1 addition & 1 deletion src/intrinsics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ static Value *emit_unbox(Type *to, const jl_cgval_t &x, jl_value_t *jt, Value *d
// bools may be stored internally as int8
unboxed = builder.CreateZExt(unboxed, T_int8);
}
else {
else if (ty != to) {
unboxed = builder.CreateBitCast(unboxed, to);
}
if (!dest)
Expand Down

0 comments on commit be88ee9

Please sign in to comment.