| ... | ... | @@ -4355,13 +4355,17 @@ pub const FuncGen = struct { |
| 4355 | 4355 | const gop = try self.func_inst_table.getOrPut(self.dg.gpa, inst); |
| 4356 | 4356 | if (gop.found_existing) return gop.value_ptr.*; |
| 4357 | 4357 | |
| 4358 | | const val = self.air.value(inst).?; |
| 4359 | | const ty = self.air.typeOf(inst); |
| 4360 | | const llvm_val = try self.dg.lowerValue(.{ .ty = ty, .val = val }); |
| 4361 | | if (!isByRef(ty)) { |
| 4362 | | gop.value_ptr.* = llvm_val; |
| 4363 | | return llvm_val; |
| 4364 | | } |
| 4358 | const llvm_val = try self.resolveValue(.{ |
| 4359 | .ty = self.air.typeOf(inst), |
| 4360 | .val = self.air.value(inst).?, |
| 4361 | }); |
| 4362 | gop.value_ptr.* = llvm_val; |
| 4363 | return llvm_val; |
| 4364 | } |
| 4365 | |
| 4366 | fn resolveValue(self: *FuncGen, tv: TypedValue) !*llvm.Value { |
| 4367 | const llvm_val = try self.dg.lowerValue(tv); |
| 4368 | if (!isByRef(tv.ty)) return llvm_val; |
| 4365 | 4369 | |
| 4366 | 4370 | // We have an LLVM value but we need to create a global constant and |
| 4367 | 4371 | // set the value as its initializer, and then return a pointer to the global. |
| ... | ... | @@ -4371,15 +4375,13 @@ pub const FuncGen = struct { |
| 4371 | 4375 | global.setLinkage(.Private); |
| 4372 | 4376 | global.setGlobalConstant(.True); |
| 4373 | 4377 | global.setUnnamedAddr(.True); |
| 4374 | | global.setAlignment(ty.abiAlignment(target)); |
| 4378 | global.setAlignment(tv.ty.abiAlignment(target)); |
| 4375 | 4379 | // Because of LLVM limitations for lowering certain types such as unions, |
| 4376 | 4380 | // the type of global constants might not match the type it is supposed to |
| 4377 | 4381 | // be, and so we must bitcast the pointer at the usage sites. |
| 4378 | | const wanted_llvm_ty = try self.dg.lowerType(ty); |
| 4382 | const wanted_llvm_ty = try self.dg.lowerType(tv.ty); |
| 4379 | 4383 | const wanted_llvm_ptr_ty = wanted_llvm_ty.pointerType(0); |
| 4380 | | const casted_ptr = global.constBitCast(wanted_llvm_ptr_ty); |
| 4381 | | gop.value_ptr.* = casted_ptr; |
| 4382 | | return casted_ptr; |
| 4384 | return global.constBitCast(wanted_llvm_ptr_ty); |
| 4383 | 4385 | } |
| 4384 | 4386 | |
| 4385 | 4387 | fn genBody(self: *FuncGen, body: []const Air.Inst.Index) Error!void { |
| ... | ... | @@ -9032,7 +9034,7 @@ pub const FuncGen = struct { |
| 9032 | 9034 | llvm_usize.constInt(@intCast(c_uint, array_info.len), .False), |
| 9033 | 9035 | }; |
| 9034 | 9036 | const elem_ptr = self.builder.buildInBoundsGEP(llvm_result_ty, alloca_inst, &indices, indices.len, ""); |
| 9035 | | const llvm_elem = try self.dg.lowerValue(.{ |
| 9037 | const llvm_elem = try self.resolveValue(.{ |
| 9036 | 9038 | .ty = array_info.elem_type, |
| 9037 | 9039 | .val = sent_val, |
| 9038 | 9040 | }); |