@@ -600,7 +600,7 @@ static void output_op_ret(struct function *fn, struct instruction *insn)
static LLVMValueRef calc_memop_addr(struct function *fn, struct instruction *insn)
{
- LLVMTypeRef int_type;
+ LLVMTypeRef int_type, addr_type;
LLVMValueRef src_p, src_i, ofs_i, addr_i, addr;
/* int type large enough to hold a pointer */
@@ -613,9 +613,10 @@ static LLVMValueRef calc_memop_addr(struct function *fn, struct instruction *ins
ofs_i = LLVMConstInt(int_type, insn->offset, 0);
addr_i = LLVMBuildAdd(fn->builder, src_i, ofs_i, "addr_i");
+ addr_type = LLVMPointerType(insn_symbol_type(fn->module, insn), 0);
+
/* convert address back to pointer */
- addr = LLVMBuildIntToPtr(fn->builder, addr_i,
- LLVMTypeOf(src_p), "addr");
+ addr = LLVMBuildIntToPtr(fn->builder, addr_i, addr_type, "addr");
return addr;
}
LLVM needs to be correctly told about the type of the object being accessed. This patch also fixes code generation for struct accesses. Cc: Pekka Enberg <penberg@kernel.org> Cc: Christopher Li <sparse@chrisli.org> Cc: Jeff Garzik <jgarzik@redhat.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Xi Wang <xi.wang@gmail.com> Signed-off-by: Jonathan Neuschäfer <j.neuschaefer@gmx.net> --- sparse-llvm.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)