[3/5] symaddr: add support for OP_SYMADDR in sparse-llvm
diff mbox

Message ID 20180309023010.94475-4-luc.vanoostenryck@gmail.com
State Under Review
Headers show

Commit Message

Luc Van Oostenryck March 9, 2018, 2:30 a.m. UTC
sparse-llvm don't yet support OP_SYMADDR instructions.

Fix this by teaching it how to handle those.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 sparse-llvm.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

Patch
diff mbox

diff --git a/sparse-llvm.c b/sparse-llvm.c
index b34decda3..095ce4c7b 100644
--- a/sparse-llvm.c
+++ b/sparse-llvm.c
@@ -989,9 +989,18 @@  static void output_insn(struct function *fn, struct instruction *insn)
 	case OP_CBR:
 		output_op_cbr(fn, insn);
 		break;
-	case OP_SYMADDR:
-		assert(0);
+	case OP_SYMADDR: {
+		LLVMValueRef res, src;
+		LLVMTypeRef dtype;
+		char name[64];
+
+		src = pseudo_to_value(fn, insn->type, insn->symbol);
+		dtype = symbol_type(insn->type);
+		pseudo_name(insn->target, name);
+		res = LLVMBuildBitCast(fn->builder, src, dtype, name);
+		insn->target->priv = res;
 		break;
+	}
 	case OP_SETVAL:
 		output_op_setval(fn, insn);
 		break;