sparse-llvm subtraction of one pointer from another should result in int difference

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

 



Hi,

I was investigating an error reported while compiling minilua (please
see my earlier post on minlua) and I found that one of the issues was
that the result of subtracting one pointer from another is not handled
correctly in sparse-llvm. I think the OP_SUB implementation should be
changed as follows:

 case OP_SUB:
  if (symbol_is_fp_type(C, insn->type))
   target = LLVMBuildFSub(fn->builder, lhs, rhs, target_name);
  else if (LLVMGetTypeKind(LLVMTypeOf(lhs)) == LLVMPointerTypeKind &&
   LLVMGetTypeKind(LLVMTypeOf(rhs)) == LLVMPointerTypeKind) {
   // Both arguments are pointer
   // Result will be integer
   lhs = LLVMBuildPtrToInt(fn->builder, lhs,
LLVMIntType(C->target->bits_in_pointer), "");
   rhs = LLVMBuildPtrToInt(fn->builder, rhs,
LLVMIntType(C->target->bits_in_pointer), "");
   target = LLVMBuildSub(fn->builder, lhs, rhs, target_name);
  }
  else
   target = LLVMBuildSub(fn->builder, lhs, rhs, target_name);
  break;

Thanks and Regards
Dibyendu
--
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