Skip to content

Commit 76edf67

Browse files
committed
ensure that constants are treated as values rather than opaque pointers
1 parent 6dd0637 commit 76edf67

File tree

2 files changed

+24
-22
lines changed

2 files changed

+24
-22
lines changed

src/codegen.cpp

+23-21
Original file line numberDiff line numberDiff line change
@@ -3808,7 +3808,29 @@ static void emit_assignment(jl_value_t *l, jl_value_t *r, jl_codectx_t *ctx)
38083808
if (vi.value.V == NULL) {
38093809
// all ghost values in destination - nothing to copy or store
38103810
}
3811-
else if (rval_info.ispointer()) {
3811+
else if (rval_info.constant || !rval_info.ispointer()) {
3812+
if (rval_info.isghost) {
3813+
// all ghost values in source - nothing to copy or store
3814+
}
3815+
else {
3816+
if (rval_info.typ != vi.value.typ && !vi.pTIndex && !rval_info.TIndex) {
3817+
// isbits cast-on-assignment is invalid. this branch should be dead-code.
3818+
CreateTrap(builder);
3819+
}
3820+
else {
3821+
Value *dest = vi.value.V;
3822+
Type *store_ty = julia_type_to_llvm(rval_info.constant ? jl_typeof(rval_info.constant) : rval_info.typ);
3823+
Type *dest_ty = store_ty->getPointerTo();
3824+
if (dest_ty != dest->getType())
3825+
dest = emit_bitcast(dest, dest_ty);
3826+
tbaa_decorate(tbaa_stack, builder.CreateStore(
3827+
emit_unbox(store_ty, rval_info, rval_info.typ),
3828+
dest,
3829+
vi.isVolatile));
3830+
}
3831+
}
3832+
}
3833+
else {
38123834
MDNode *tbaa = rval_info.tbaa;
38133835
// the memcpy intrinsic does not allow to specify different alias tags
38143836
// for the load part (x.tbaa) and the store part (tbaa_stack).
@@ -3833,26 +3855,6 @@ static void emit_assignment(jl_value_t *l, jl_value_t *r, jl_codectx_t *ctx)
38333855
vi.isVolatile,
38343856
tbaa);
38353857
}
3836-
else if (rval_info.V == NULL) {
3837-
// all ghost values in source - nothing to copy or store
3838-
}
3839-
else {
3840-
if (rval_info.typ != vi.value.typ && !vi.pTIndex && !rval_info.TIndex) {
3841-
// isbits cast-on-assignment is invalid. this branch should be dead-code.
3842-
CreateTrap(builder);
3843-
}
3844-
else {
3845-
Value *dest = vi.value.V;
3846-
Type *store_ty = julia_type_to_llvm(rval_info.typ);
3847-
Type *dest_ty = store_ty->getPointerTo();
3848-
if (dest_ty != dest->getType())
3849-
dest = emit_bitcast(dest, dest_ty);
3850-
tbaa_decorate(tbaa_stack, builder.CreateStore(
3851-
emit_unbox(store_ty, rval_info, rval_info.typ),
3852-
dest,
3853-
vi.isVolatile));
3854-
}
3855-
}
38563858
}
38573859
else {
38583860
assert(vi.pTIndex == NULL);

src/intrinsics.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ static Value *emit_unbox(Type *to, const jl_cgval_t &x, jl_value_t *jt, Value *d
301301
// bools may be stored internally as int8
302302
unboxed = builder.CreateZExt(unboxed, T_int8);
303303
}
304-
else {
304+
else if (ty != to) {
305305
unboxed = builder.CreateBitCast(unboxed, to);
306306
}
307307
if (!dest)

0 commit comments

Comments
 (0)