Re: [PATCH 06/13] llvm: fix type of literal integer passed as arguments

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, Mar 5, 2017 at 7:20 PM, Luc Van Oostenryck
<luc.vanoostenryck@xxxxxxxxx> wrote:
> Like for all others instructions, LLVM needs the type
> of each operands. However this information is not always
> available via the pseudo, like here when passing a integer
> constant as argument since for sparse constants are typeless.
>
> Fix this by getting the type via the function prototype.
>
> +               LLVMValueRef value;
> +               if (arg->type == PSEUDO_VAL) {
> +                       /* Value pseudos do not have type information. */
> +                       /* Use the function prototype to get the type. */
> +                       struct symbol *ctype = get_nth1_arg(insn->func->sym, i + 1);

I try to come up with an example to use the PREPARE_PTR_LIST() in this patch.
I hit a bug "insn->func->sym"  assume "insn->func" is a function symbol node.
If "insn->func" is a function pointer then access "insn->func->sym" is wrong.

Any way, my modify patch attached. It should work similar to this patch
without using the nth argument help function. My limited test hit this
function pointer bug.


Chris
From patchwork Sun Mar  5 11:20:40 2017
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Subject: [06/13] llvm: fix type of literal integer passed as arguments
From: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx>
X-Patchwork-Id: 9604557
Message-Id: <20170305112047.3411-7-luc.vanoostenryck@xxxxxxxxx>
To: linux-sparse@xxxxxxxxxxxxxxx
Cc: Dibyendu Majumdar <mobile@xxxxxxxxxxxxxxx>,
 Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx>
Date: Sun,  5 Mar 2017 12:20:40 +0100

Like for all others instructions, LLVM needs the type
of each operands. However this information is not always
available via the pseudo, like here when passing a integer
constant as argument since for sparse constants are typeless.

Fix this by getting the type via the function prototype.

Reported-by: Dibyendu Majumdar <mobile@xxxxxxxxxxxxxxx>
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx>
---
 sparse-llvm.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)



--- sparse.chrisl.orig/sparse-llvm.c
+++ sparse.chrisl/sparse-llvm.c
@@ -729,6 +729,8 @@ static void output_op_call(struct functi
 {
 	LLVMValueRef target, func;
 	int n_arg = 0, i;
+	struct symbol_list *argument_types = insn->func->sym->ctype.base_type->arguments;
+	struct symbol *argtype;
 	struct pseudo *arg;
 	LLVMValueRef *args;
 
@@ -739,9 +741,20 @@ static void output_op_call(struct functi
 	args = calloc(n_arg, sizeof(LLVMValueRef));
 
 	i = 0;
+	PREPARE_PTR_LIST(argument_types, argtype);
 	FOR_EACH_PTR(insn->arguments, arg) {
-		args[i++] = pseudo_to_value(fn, insn, arg);
+		LLVMValueRef value;
+		if (arg->type == PSEUDO_VAL) {
+			/* Value pseudos do not have type information. */
+			/* Use the function prototype to get the type. */
+			value = val_to_value(fn, arg->value, argtype);
+		} else {
+			value = pseudo_to_value(fn, insn, arg);
+		}
+		args[i++] = value;
+		NEXT_PTR_LIST(argtype);
 	} END_FOR_EACH_PTR(arg);
+	FINISH_PTR_LIST(argtype);
 
 	func = pseudo_to_value(fn, insn, insn->func);
 	target = LLVMBuildCall(fn->builder, func, args, n_arg, "");

[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux