All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dibyendu Majumdar <mobile@majumdar.org.uk>
To: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Cc: Linux-Sparse <linux-sparse@vger.kernel.org>
Subject: Re: Sparse-LLVM issue compiling NULL pointers
Date: Thu, 2 Mar 2017 16:39:38 +0000	[thread overview]
Message-ID: <CACXZuxemR+d9J+PZN0wpUOSFS8eP+1QhzM=YiJQ13xV3hYKvJQ@mail.gmail.com> (raw)
In-Reply-To: <20170302052124.fsqogvysufayy4to@macbook.local>

Hi Luc,

On 2 March 2017 at 05:21, Luc Van Oostenryck
<luc.vanoostenryck@gmail.com> wrote:
> On Wed, Mar 01, 2017 at 02:45:03PM +0000, Dibyendu Majumdar wrote:
>> On 1 March 2017 at 10:58, Dibyendu Majumdar <mobile@majumdar.org.uk> wrote:
>> > On 28 February 2017 at 17:03, Luc Van Oostenryck
>> > <luc.vanoostenryck@gmail.com> wrote:
>> >> On Tue, Feb 28, 2017 at 4:09 PM, Luc Van Oostenryck
>> >> <luc.vanoostenryck@gmail.com> wrote:
>> >>> There is indeed some problems regarding this, we looked a bit at this
>> >>> some weeks ago. However I firmly believe that the information about
>> >>> the type belong to the operations and not the values.
>> >>
>> >
>> > I am trying to work out how a value pseudo correct type can be
>> > determined when the pseudo is a function call argument. Would
>> > appreciate any pointers on this. The current implementation of
>> > pseudo_to_value() uses the function call instruction which is
>> > incorrect.
>> >
>>
>> I have implemented a solution that get the type information from the
>> function prototype for pseudo values when processing function
>> arguments, but not sure this is correct.
>
> You need something like:
> +struct symbol *argument_type(pseudo_t src)
> +{
> +       struct entrypoint *ep = src->def->bb->ep;
> +       struct symbol_list *args = ep->name->ctype.base_type->arguments;
> +       struct symbol *arg;
> +       int i = 0;
> +       FOR_EACH_PTR(args, arg) {
> +               if (++i == src->nr)
> +                       return arg;
> +       } END_FOR_EACH_PTR(arg);
> +
> +       assert(0);
> +}
>
>> Anyway have hit a bunch of other issues with sparse-llvm ... :-(
>
> Each day its problem (and happily its solution too!).
>

I am using the following fix. There is some noise below as this code
is from modified version.


static LLVMValueRef pseudo_val_to_value(struct dmr_C *C, struct
function *fn, LLVMTypeRef type, pseudo_t pseudo)
{
 assert(pseudo->type == PSEUDO_VAL);
 LLVMValueRef result = NULL;
 switch (LLVMGetTypeKind(type)) {
 case LLVMPointerTypeKind:
  if (pseudo->value == 0)
   result = LLVMConstPointerNull(type);
  else
   result = LLVMConstIntToPtr(
    LLVMConstInt(
     LLVMIntType(C->target->bits_in_pointer),
     pseudo->value, 1),
    type);
  break;
 case LLVMIntegerTypeKind:
  result = LLVMConstInt(type, pseudo->value, 1);
  break;
 default:
  assert(0);
 }
 // ORIGINAL result = LLVMConstInt(type, pseudo->value, 1);
 // PREVIOUS FIX result = LLVMConstInt(LLVMInt64Type(), pseudo->value, 1);
 return result;
}

static LLVMValueRef pseudo_to_value(struct dmr_C *C, struct function
*fn, struct instruction *insn, pseudo_t pseudo)
{
 ...
 case PSEUDO_VAL: {
  LLVMTypeRef type = insn_symbol_type(C, fn->module, insn);
  result = pseudo_val_to_value(C, fn, type, pseudo);
  break;
 }
 ...
}

static void output_op_call(struct dmr_C *C, struct function *fn,
struct instruction *insn)
{
 LLVMValueRef target, func;
 int n_arg = 0, i;
 struct pseudo *arg;
 LLVMValueRef *args;
 pseudo_t function_proto = insn->func;
 int n_proto_args = 0;
 struct symbol *proto_symbol = function_proto->sym->ctype.base_type;
 struct symbol *proto_arg;
 struct symbol **proto_args;
 /* count function prototype args, get prototype argument symbols */
 FOR_EACH_PTR(proto_symbol->arguments, proto_arg) {
  n_proto_args++;
 } END_FOR_EACH_PTR(proto_arg);
 proto_args = alloca(n_proto_args * sizeof(struct symbol *));
 int idx = 0;
 FOR_EACH_PTR(proto_symbol->arguments, proto_arg) {
  proto_args[idx++] = proto_arg->ctype.base_type;
 } END_FOR_EACH_PTR(proto_arg);
 n_arg = 0;
 FOR_EACH_PTR(insn->arguments, arg) {
  n_arg++;
 } END_FOR_EACH_PTR(arg);
 if (n_arg != n_proto_args) {
  fprintf(stderr, "Mismatch in function arguments\n");
  abort();
 }
 args = alloca(n_arg * sizeof(LLVMValueRef));
 i = 0;
 FOR_EACH_PTR(insn->arguments, arg) {
  if (arg->type == PSEUDO_VAL) {
   /* as value pseudo do not have type information we use the
      function prototype to decide types */
   LLVMTypeRef type = symbol_type(C, fn->module, proto_args[i]);
   args[i] = pseudo_val_to_value(C, fn, type, arg);
  }
  else {
   args[i] = pseudo_to_value(C, fn, insn, arg);
  }
  i++;
 } END_FOR_EACH_PTR(arg);
 func = pseudo_to_value(C, fn, insn, insn->func);
 target = LLVMBuildCall(fn->builder, func, args, n_arg, "");
 insn->target->priv = target;
}

  parent reply	other threads:[~2017-03-02 16:48 UTC|newest]

Thread overview: 57+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-28  6:20 Sparse-LLVM issue compiling NULL pointers Dibyendu Majumdar
2017-02-28 15:09 ` Luc Van Oostenryck
2017-02-28 16:04   ` Dibyendu Majumdar
2017-02-28 16:47     ` Luc Van Oostenryck
2017-02-28 16:49     ` Dibyendu Majumdar
2017-03-02  6:48       ` Luc Van Oostenryck
2017-02-28 17:03   ` Luc Van Oostenryck
2017-02-28 17:35     ` Luc Van Oostenryck
2017-02-28 17:42       ` Dibyendu Majumdar
2017-02-28 18:08       ` Dibyendu Majumdar
2017-03-01  5:49         ` Luc Van Oostenryck
2017-03-02  7:02         ` [PATCH] llvm: fix getting type of values Luc Van Oostenryck
2017-03-01 10:58     ` Sparse-LLVM issue compiling NULL pointers Dibyendu Majumdar
2017-03-01 14:45       ` Dibyendu Majumdar
2017-03-02  5:21         ` Luc Van Oostenryck
2017-03-02  5:41           ` Dibyendu Majumdar
2017-03-02 13:56             ` Luc Van Oostenryck
2017-03-02 14:05               ` Dibyendu Majumdar
2017-03-02 16:10                 ` Luc Van Oostenryck
2017-03-02 14:33               ` Dibyendu Majumdar
2017-03-02 16:04                 ` Luc Van Oostenryck
2017-03-02 16:29                   ` Dibyendu Majumdar
2017-03-02 16:30                     ` Dibyendu Majumdar
2017-03-02 17:18                       ` Luc Van Oostenryck
2017-03-02 17:36                         ` Dibyendu Majumdar
2017-03-02 20:09                         ` Luc Van Oostenryck
2017-03-03  2:52                           ` Dibyendu Majumdar
2017-03-03  3:01                             ` Dibyendu Majumdar
2017-03-03  4:03                               ` Dibyendu Majumdar
2017-03-03  5:24                                 ` [PATCH] llvm: fix output_op_[ptr]cast() Luc Van Oostenryck
2017-03-03  7:37                                   ` Dibyendu Majumdar
2017-03-03 18:06                                     ` Dibyendu Majumdar
2017-03-03 18:30                                       ` Dibyendu Majumdar
2017-03-03 19:55                                         ` Luc Van Oostenryck
2017-03-06  1:56                                           ` Christopher Li
2017-03-03 19:50                                       ` Luc Van Oostenryck
2017-03-03 19:54                                         ` Dibyendu Majumdar
2017-03-03 20:52                                           ` [PATCH] llvm: fix: do not mix pointers and floats when doing compares Luc Van Oostenryck
2017-03-03  4:16                             ` Sparse-LLVM issue compiling NULL pointers Luc Van Oostenryck
2017-03-03  4:27                             ` Luc Van Oostenryck
2017-03-03  4:38                               ` Dibyendu Majumdar
2017-03-03  7:50                                 ` Luc Van Oostenryck
2017-03-03 12:39                                   ` Dibyendu Majumdar
2017-03-02 17:03                     ` Dibyendu Majumdar
2017-03-02 17:18                       ` Dibyendu Majumdar
2017-03-02 17:43                         ` Luc Van Oostenryck
2017-03-02 18:58                           ` Dibyendu Majumdar
2017-03-02 19:34                             ` Luc Van Oostenryck
2017-03-02 17:50                       ` Luc Van Oostenryck
2017-03-02 17:57                         ` Luc Van Oostenryck
2017-03-02 18:02                           ` Dibyendu Majumdar
2017-03-03  4:21                             ` Luc Van Oostenryck
2017-03-02 17:27                   ` Luc Van Oostenryck
2017-03-02 18:41                   ` Dibyendu Majumdar
2017-03-03  5:35                     ` Luc Van Oostenryck
2017-03-02 16:39           ` Dibyendu Majumdar [this message]
2017-03-02 17:21             ` Luc Van Oostenryck

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CACXZuxemR+d9J+PZN0wpUOSFS8eP+1QhzM=YiJQ13xV3hYKvJQ@mail.gmail.com' \
    --to=mobile@majumdar.org.uk \
    --cc=linux-sparse@vger.kernel.org \
    --cc=luc.vanoostenryck@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.