diff options
| author | Pekka Enberg <penberg@kernel.org> | 2011-11-22 17:27:54 +0200 |
|---|---|---|
| committer | Pekka Enberg <penberg@kernel.org> | 2011-11-22 17:27:54 +0200 |
| commit | 2b67f8548ad54267e6c53a9d22f9f16affd07e97 (patch) | |
| tree | 556db3ad04dfa2151d723262e6de9b361146e1cb | |
| parent | 7101fe01404bbd985471122258b952abeaa0845b (diff) | |
| download | sparse-dev-2b67f8548ad54267e6c53a9d22f9f16affd07e97.tar.gz | |
sparse, llvm: Pointer cast code generation
This patch implement code generation for OP_PTRCAST using LLVMBuildBitCast().
Cc: Christopher Li <sparse@chrisli.org>
Cc: Jeff Garzik <jgarzik@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
| -rw-r--r-- | sparse-llvm.c | 20 | ||||
| -rw-r--r-- | validation/backend/ptrcast.c | 9 |
2 files changed, 28 insertions, 1 deletions
diff --git a/sparse-llvm.c b/sparse-llvm.c index 1a2a34db..e3d8883a 100644 --- a/sparse-llvm.c +++ b/sparse-llvm.c @@ -812,6 +812,24 @@ static void output_op_phi(struct function *fn, struct instruction *insn) insn->target->priv = target; } +static void output_op_ptrcast(struct function *fn, struct instruction *insn) +{ + LLVMValueRef src, target; + char target_name[64]; + + src = insn->src->priv; + if (!src) + src = pseudo_to_value(fn, insn, insn->src); + + pseudo_name(insn->target, target_name); + + assert(!symbol_is_fp_type(insn->type)); + + target = LLVMBuildBitCast(fn->builder, src, insn_symbol_type(fn->module, insn), target_name); + + insn->target->priv = target; +} + static void output_op_cast(struct function *fn, struct instruction *insn, LLVMOpcode op) { LLVMValueRef src, target; @@ -917,7 +935,7 @@ static void output_insn(struct function *fn, struct instruction *insn) assert(0); break; case OP_PTRCAST: - assert(0); + output_op_ptrcast(fn, insn); break; case OP_BINARY ... OP_BINARY_END: case OP_BINCMP ... OP_BINCMP_END: diff --git a/validation/backend/ptrcast.c b/validation/backend/ptrcast.c new file mode 100644 index 00000000..46f8add8 --- /dev/null +++ b/validation/backend/ptrcast.c @@ -0,0 +1,9 @@ +static char *ptrcast(unsigned long *x) +{ + return (unsigned char *) x; +} + +/* + * check-name: Pointer cast code generation + * check-command: ./sparsec -c $file -o tmp.o + */ |
