Re: sparse-llvm incorrect type when ealing with union type

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

 



On 13 March 2017 at 22:54, Dibyendu Majumdar <mobile@xxxxxxxxxxxxxxx> 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);
--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[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