@@ -1775,7 +1775,7 @@ static jl_cgval_t emit_new_struct(jl_codectx_t &ctx, jl_value_t *ty, size_t narg
17751775static jl_cgval_t emit_invoke (jl_codectx_t &ctx, const jl_cgval_t &lival, const jl_cgval_t *argv, size_t nargs, jl_value_t *rt);
17761776
17771777static Value *literal_pointer_val (jl_codectx_t &ctx, jl_value_t *p);
1778- static GlobalVariable * prepare_global_in (Module *M, GlobalVariable *G );
1778+ static unsigned julia_alignment ( jl_value_t *jt );
17791779
17801780static GlobalVariable *prepare_global_in (Module *M, JuliaVariable *G)
17811781{
@@ -1813,7 +1813,7 @@ static inline GlobalVariable *prepare_global_in(Module *M, GlobalVariable *G)
18131813
18141814// --- convenience functions for tagging llvm values with julia types ---
18151815
1816- static GlobalVariable *get_pointer_to_constant (jl_codegen_params_t &emission_context, Constant *val, const Twine &name, Module &M)
1816+ static GlobalVariable *get_pointer_to_constant (jl_codegen_params_t &emission_context, Constant *val, Align align, const Twine &name, Module &M)
18171817{
18181818 GlobalVariable *&gv = emission_context.mergedConstants [val];
18191819 auto get_gv = [&](const Twine &name) {
@@ -1825,6 +1825,7 @@ static GlobalVariable *get_pointer_to_constant(jl_codegen_params_t &emission_con
18251825 val,
18261826 name);
18271827 gv->setUnnamedAddr (GlobalValue::UnnamedAddr::Global);
1828+ gv->setAlignment (align);
18281829 return gv;
18291830 };
18301831 if (gv == nullptr ) {
@@ -1945,7 +1946,8 @@ static inline jl_cgval_t value_to_pointer(jl_codectx_t &ctx, Value *v, jl_value_
19451946{
19461947 Value *loc;
19471948 if (valid_as_globalinit (v)) { // llvm can't handle all the things that could be inside a ConstantExpr
1948- loc = get_pointer_to_constant (ctx.emission_context , cast<Constant>(v), " _j_const" , *jl_Module);
1949+ assert (jl_is_concrete_type (typ)); // not legal to have an unboxed abstract type
1950+ loc = get_pointer_to_constant (ctx.emission_context , cast<Constant>(v), Align (julia_alignment (typ)), " _j_const" , *jl_Module);
19491951 }
19501952 else {
19511953 loc = emit_static_alloca (ctx, v->getType ());
@@ -2319,7 +2321,7 @@ static jl_cgval_t convert_julia_type(jl_codectx_t &ctx, const jl_cgval_t &v, jl_
23192321 new_tindex = ConstantInt::get (getInt8Ty (ctx.builder .getContext ()), new_idx);
23202322 if (v.V && !v.ispointer ()) {
23212323 // TODO: remove this branch once all consumers of v.TIndex understand how to handle a non-ispointer value
2322- return value_to_pointer (ctx, v. V , typ, new_tindex);
2324+ return jl_cgval_t ( value_to_pointer (ctx, v) , typ, new_tindex);
23232325 }
23242326 }
23252327 else if (jl_subtype (v.typ , typ)) {
@@ -7672,7 +7674,7 @@ static jl_llvm_functions_t
76727674 Type *vtype = julia_type_to_llvm (ctx, jt, &isboxed);
76737675 assert (!isboxed);
76747676 assert (!type_is_ghost (vtype) && " constants should already be handled" );
7675- Value *lv = new AllocaInst (vtype, M->getDataLayout ().getAllocaAddrSpace (), NULL , Align (jl_datatype_align (jt)), jl_symbol_name (s), /* InsertBefore*/ ctx.topalloca );
7677+ Value *lv = new AllocaInst (vtype, M->getDataLayout ().getAllocaAddrSpace (), nullptr , Align (jl_datatype_align (jt)), jl_symbol_name (s), /* InsertBefore*/ ctx.topalloca );
76767678 if (CountTrackedPointers (vtype).count ) {
76777679 StoreInst *SI = new StoreInst (Constant::getNullValue (vtype), lv, false , Align (sizeof (void *)));
76787680 SI->insertAfter (ctx.topalloca );
@@ -7692,7 +7694,7 @@ static jl_llvm_functions_t
76927694 (va && (int )i == ctx.vaSlot ) || // or it's the va arg tuple
76937695 i == 0 ) { // or it is the first argument (which isn't in `argArray`)
76947696 AllocaInst *av = new AllocaInst (ctx.types ().T_prjlvalue , M->getDataLayout ().getAllocaAddrSpace (),
7695- jl_symbol_name (s), /* InsertBefore*/ ctx.topalloca );
7697+ nullptr , Align ( sizeof ( jl_value_t *)), jl_symbol_name (s), /* InsertBefore*/ ctx.topalloca );
76967698 StoreInst *SI = new StoreInst (Constant::getNullValue (ctx.types ().T_prjlvalue ), av, false , Align (sizeof (void *)));
76977699 SI->insertAfter (ctx.topalloca );
76987700 varinfo.boxroot = av;
0 commit comments