diff --git a/src/cgutils.cpp b/src/cgutils.cpp index c0119a29be0d3..0a314baec3229 100644 --- a/src/cgutils.cpp +++ b/src/cgutils.cpp @@ -540,12 +540,14 @@ static Type *julia_struct_to_llvm(jl_value_t *jt, jl_unionall_t *ua, bool *isbox else if (jl_is_uniontype(ty)) { // pick an Integer type size such that alignment will be correct // and always end with an Int8 (selector byte) - Type *lty0 = ArrayType::get(IntegerType::get(jl_LLVMContext, 8 * al), (fsz - 1) / al); - latypes.push_back(lty0); - latypes.push_back(T_int8); + Type *AlignmentType = IntegerType::get(jl_LLVMContext, 8 * al); + unsigned NumATy = (fsz - 1) / al; unsigned remainder = (fsz - 1) % al; + while (NumATy--) + latypes.push_back(AlignmentType); while (remainder--) latypes.push_back(T_int8); + latypes.push_back(T_int8); isarray = false; allghost = false; continue; diff --git a/src/intrinsics.cpp b/src/intrinsics.cpp index 4730cdd37aea1..db06dc3441560 100644 --- a/src/intrinsics.cpp +++ b/src/intrinsics.cpp @@ -208,39 +208,43 @@ static Constant *julia_const_to_llvm(const void *ptr, jl_datatype_t *bt) uint8_t sel = ((const uint8_t*)ptr)[offs + fsz - 1]; jl_value_t *active_ty = jl_nth_union_component(ft, sel); size_t active_sz = jl_datatype_size(active_ty); - ArrayType *aty = cast(lct->getTypeAtIndex(llvm_idx)); - unsigned num_array_elem = aty->getNumElements(); - assert(aty->getElementType() == IntegerType::get(jl_LLVMContext, 8 * al) && - num_array_elem == (fsz - 1) / al); - std::vector ArrayElements(num_array_elem); - for (unsigned j = 0; j < num_array_elem; j++) { - APInt Elem(8 * al, 0); - void *bits = const_cast(Elem.getRawData()); - if (active_sz > al) { - memcpy(bits, ov, al); - active_sz -= al; + Type *AlignmentType = IntegerType::get(jl_LLVMContext, 8 * al); + unsigned NumATy = (fsz - 1) / al; + unsigned remainder = (fsz - 1) % al; + while (NumATy--) { + Constant *fld; + if (active_sz > 0) { + APInt Elem(8 * al, 0); + void *bits = const_cast(Elem.getRawData()); + if (active_sz > al) { + memcpy(bits, ov, al); + active_sz -= al; + } + else { + memcpy(bits, ov, active_sz); + active_sz = 0; + } + fld = ConstantInt::get(AlignmentType, Elem); } - else if (active_sz > 0) { - memcpy(bits, ov, active_sz); - active_sz = 0; + else { + fld = UndefValue::get(AlignmentType); } ov += al; - ArrayElements[j] = ConstantInt::get(aty->getElementType(), Elem); + fields.push_back(fld); } - fields.push_back(ConstantArray::get(aty, ArrayElements)); - unsigned remainder = (fsz - 1) % al; while (remainder--) { - uint8_t byte; + Constant *fld; if (active_sz > 0) { - byte = *ov; + uint8_t byte = *ov; + APInt Elem(8, byte); active_sz -= 1; + fld = ConstantInt::get(T_int8, Elem); } else { - byte = 0; + fld = UndefValue::get(T_int8); } ov += 1; - APInt Elem(8, byte); - fields.push_back(ConstantInt::get(T_int8, Elem)); + fields.push_back(fld); } fields.push_back(ConstantInt::get(T_int8, sel)); }