diff mbox

[3/4] sparse, llvm: base load/store address type on insn_symbol_type()

Message ID 1368899527-2350-3-git-send-email-j.neuschaefer@gmx.net (mailing list archive)
State Mainlined, archived
Headers show

Commit Message

Jonathan Neuschäfer May 18, 2013, 5:52 p.m. UTC
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(-)
diff mbox

Patch

diff --git a/sparse-llvm.c b/sparse-llvm.c
index 8573eda..a8ebeab 100644
--- a/sparse-llvm.c
+++ b/sparse-llvm.c
@@ -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;
 }