Re: Sparse-LLVM issue compiling NULL pointers

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

 



On 3 March 2017 at 03:01, Dibyendu Majumdar <mobile@xxxxxxxxxxxxxxx> wrote:
>> Next problem:
>>
>> The following fails.
>>
>> typedef unsigned long long size_t;
>> struct buffer_type_st {
>>  struct buffer_type_st    *next_buffer;
>>  char           *buffer;
>> };
>> typedef struct buffer_type_st buffer_type_t;
>> struct link_st {
>>  struct link_st           *next;
>> };
>> typedef struct link_st link_t;
>> struct allocator_st {
>>  buffer_type_t    *buffer_list;
>>  link_t           *free_list;
>>  char           *next_avail;
>>  char           *last;
>>  size_t          size;
>>  size_t          n;
>> };
>> typedef struct allocator_st allocator;
>> extern void *
>> alloc_node(allocator * a);
>> extern void
>> grow_allocator(allocator * a);
>> void *
>> alloc_node(allocator * a)
>> {
>>  link_t           *tmp;
>>  tmp = a->free_list;
>>  return (void *) tmp;
>> }
>>
>>
>> I get LLVM assertion failure for following instruction:
>>
>> insn cast.64     %r4 <- (64) %r2
>>
>> Assertion failed: isa<X>(Val) && "cast<Ty>() argument of incompatible
>> type!", file C:\d\llvm-3.9.0.src\include\llvm/Support/Casting.h, line
>> 237
>>
>> I think this is because the linearize is outputting an integer cast
>> rather than pointer cast so LLVM is not happy.
>>
>
> Simpler example:
>
> void *
> alloc_node(void)
> {
>  char *tmp;
>  tmp = (void *)0;
>  return tmp;
> }

I tried the following fix in sparse-llvm.c. It handles pointer casts
in output_op_cast. While this fixes the simpler example I get a
different error now on the larger sample.

static void output_op_cast(struct dmr_C *C, struct function *fn,
struct instruction *insn, LLVMOpcode op)
{
 LLVMValueRef src, target;
 char target_name[64];
 src = insn->src->priv;
 if (!src)
  src = pseudo_to_value(C, fn, insn, insn->src);
 pseudo_name(C, insn->target, target_name);
 assert(!symbol_is_fp_type(C, insn->type));
 if (LLVMGetTypeKind(LLVMTypeOf(src)) == LLVMPointerTypeKind) {
  target = LLVMBuildBitCast(fn->builder, src, insn_symbol_type(C,
fn->module, insn), target_name);
 }
 else {
  if (insn->size < LLVMGetIntTypeWidth(LLVMTypeOf(src)))
   target = LLVMBuildTrunc(fn->builder, src, insn_symbol_type(C,
fn->module, insn), target_name);
  else
   target = LLVMBuildCast(fn->builder, op, src, insn_symbol_type(C,
fn->module, insn), target_name);
 }
 insn->target->priv = target;
}
--
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