Skip to content

Commit 3dc1419

Browse files
committed
Fix crash in Dict test
Now, that bottom is a leaftype, we need to be careful not to assume that all leaf types are datatypes. Fix the specific instance that caused the crash in array.c and audit other uses, inserting appropriate assertions.
1 parent 6da9ad5 commit 3dc1419

File tree

5 files changed

+20
-11
lines changed

5 files changed

+20
-11
lines changed

src/array.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ extern "C" {
2424

2525
static inline int store_unboxed(jl_value_t *el_type) // jl_isbits
2626
{
27-
return jl_is_leaf_type(el_type) && jl_is_immutable(el_type) &&
28-
((jl_datatype_t*)el_type)->layout && ((jl_datatype_t*)el_type)->layout->pointerfree;
27+
return jl_is_leaf_type(el_type) && el_type != jl_bottom_type &&
28+
jl_is_immutable(el_type) && ((jl_datatype_t*)el_type)->layout &&
29+
((jl_datatype_t*)el_type)->layout->pointerfree;
2930
}
3031

3132
int jl_array_store_unboxed(jl_value_t *el_type)

src/cgutils.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ static DIType julia_type_to_di(jl_value_t *jt, DIBuilder *dbuilder, bool isboxed
212212
return ct;
213213
}
214214
else {
215+
assert(jl_is_datatype(jt));
215216
jdt->ditype = dbuilder->createTypedef(jl_pvalue_dillvmt,
216217
jl_symbol_name(jdt->name->name), NULL, 0, NULL);
217218
return (llvm::DIType*)jdt->ditype;

src/codegen.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2750,6 +2750,7 @@ static bool emit_builtin_call(jl_cgval_t *ret, jl_value_t *f, jl_value_t **args,
27502750
sz = emit_datatype_nfields(boxed(arg1, ctx));
27512751
}
27522752
else {
2753+
assert(jl_is_datatype(aty));
27532754
sz = ConstantInt::get(T_size, jl_datatype_nfields(aty));
27542755
}
27552756
*ret = mark_julia_type(sz, false, jl_long_type, ctx);
@@ -2832,6 +2833,7 @@ static bool emit_builtin_call(jl_cgval_t *ret, jl_value_t *f, jl_value_t **args,
28322833
JL_GC_POP();
28332834
return false;
28342835
}
2836+
assert(jl_is_datatype(stt));
28352837

28362838
ssize_t fieldidx = -1;
28372839
if (jl_is_quotenode(args[2]) && jl_is_symbol(jl_fieldref(args[2], 0))) {

src/jltypes.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -881,13 +881,18 @@ static jl_value_t *inst_datatype(jl_datatype_t *dt, jl_svec_t *p, jl_value_t **i
881881
size_t i;
882882
for(i=0; i < ntp; i++) {
883883
jl_value_t *pi = iparams[i];
884-
if (!jl_is_leaf_type(pi) || ((jl_datatype_t*)pi)->abstract) {
885-
// normalize types equal to wrappers
886-
jl_value_t *tw = extract_wrapper(pi);
887-
if (tw && tw != pi && jl_types_equal(pi, tw)) {
888-
iparams[i] = tw;
889-
if (p) jl_gc_wb(p, tw);
890-
}
884+
if (pi == jl_bottom_type)
885+
continue;
886+
if (jl_is_leaf_type(pi)) {
887+
assert(jl_is_datatype(pi));
888+
if (!((jl_datatype_t*)pi)->abstract)
889+
continue;
890+
}
891+
// normalize types equal to wrappers
892+
jl_value_t *tw = extract_wrapper(pi);
893+
if (tw && tw != pi && jl_types_equal(pi, tw)) {
894+
iparams[i] = tw;
895+
if (p) jl_gc_wb(p, tw);
891896
}
892897
}
893898
jl_value_t *lkup = (jl_value_t*)lookup_type(tn, iparams, ntp);

src/subtype.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,9 @@ static int obviously_unequal(jl_value_t *a, jl_value_t *b)
191191
{
192192
if (a == b)
193193
return 0;
194-
if (jl_is_leaf_type(a) && !((jl_datatype_t*)a)->abstract)
194+
if (a != jl_bottom_type && jl_is_leaf_type(a) && !((jl_datatype_t*)a)->abstract)
195195
return 1;
196-
if (jl_is_leaf_type(b) && !((jl_datatype_t*)b)->abstract)
196+
if (b != jl_bottom_type && jl_is_leaf_type(b) && !((jl_datatype_t*)b)->abstract)
197197
return 1;
198198
if (jl_is_unionall(a)) a = jl_unwrap_unionall(a);
199199
if (jl_is_unionall(b)) b = jl_unwrap_unionall(b);

0 commit comments

Comments
 (0)