All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dibyendu Majumdar <mobile@majumdar.org.uk>
To: Linux-Sparse <linux-sparse@vger.kernel.org>
Subject: Re: sparse-llvm incorrect type when ealing with union type
Date: Mon, 13 Mar 2017 23:44:12 +0000	[thread overview]
Message-ID: <CACXZuxeXy7nw8WCHfWnj72NaMxd8yn0vF4CL+EvfnJk5CNSd=g@mail.gmail.com> (raw)
In-Reply-To: <CACXZuxcb=27brA9N=w-tnZ9V0StKnDYZ4y27cS6eoenA7S0ctw@mail.gmail.com>

On 13 March 2017 at 22:54, Dibyendu Majumdar <mobile@majumdar.org.uk> wrote:
> I am investigating a type error in LLVM. Here is the snippet of code:
>
> typedef union GCObject GCObject;
> typedef unsigned char lu_byte;
> typedef double lua_Number;
> typedef union {
>  GCObject *gc;
>  void *p;
>  lua_Number n;
>  int b;
> } Value;
> typedef struct lua_TValue {
>  Value value;
>  int tt;
> } TValue;
> typedef struct UpVal {
>  GCObject *next;
>  lu_byte tt;
>  lu_byte marked;
>  TValue *v;
>  union {
>   TValue value;
>   struct {
>    struct UpVal *prev;
>    struct UpVal *next;
>   } l;
>  } u;
> } UpVal;
> static void close(UpVal *uv)
> {
>  uv->v = &uv->u.value;
> }
>
> The linearized output is:
>
> close:
> .L0:
>         <entry-point>
>         add.64      %r2 <- %arg1, $24
>         store.64    %r2 -> 16[%arg1]
>         ret
>
> The result of the add operation ends up the same type as arg1 which is
> UpVal*. But this is then assigned to uv->v which is expected to be
> TValue*. So LLVM doesn't like it.
>
> While in this case we could cast to the expected value before the
> store - I am worried that in other cases where the value is read and
> used somewhere it will have the wrong type.
>
> I see that the add instruction's type is 'void *'.
>
> Any suggestions on how to solve this issue?
>

For now I am casting the stored value in output_op_store():

 target_in = pseudo_to_value(C, fn, insn, insn->target);
 desttype = insn_symbol_type(C, fn->module, insn);

 /* Cast to the right type - to resolve issue with union types */
 target_in = LLVMBuildBitCast(fn->builder, target_in, desttype, "");
 /* perform store */
 LLVMBuildStore(fn->builder, target_in, addr);

  reply	other threads:[~2017-03-13 23:44 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-13 22:54 sparse-llvm incorrect type when ealing with union type Dibyendu Majumdar
2017-03-13 23:44 ` Dibyendu Majumdar [this message]
2017-03-14  1:29   ` Dibyendu Majumdar
2017-03-19 15:36 ` Luc Van Oostenryck
2017-03-19 15:54   ` Dibyendu Majumdar
2017-03-19 16:37   ` Dibyendu Majumdar
2017-03-19 17:15     ` Luc Van Oostenryck
2017-03-19 17:55       ` Dibyendu Majumdar
2017-03-19 20:48         ` Dibyendu Majumdar

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='CACXZuxeXy7nw8WCHfWnj72NaMxd8yn0vF4CL+EvfnJk5CNSd=g@mail.gmail.com' \
    --to=mobile@majumdar.org.uk \
    --cc=linux-sparse@vger.kernel.org \
    /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.