[LLVMdev] [Compiler-RT] [ARM] Where __aeabi_[il]div0 builtins should be implemented?

Renato Golin renato.golin at linaro.org
Wed Sep 10 02:40:32 PDT 2014


On 10 September 2014 06:39, Saleem Abdulrasool <compnerd at compnerd.org> wrote:
> Oh!  I think I see what the confusion is all about.  __aeabi_[il]div0 are
> *NOT* division routines.

Hi Saleem,

No, that's not the confusion. The {i,l}div0 functions are public and
can be called from anywhere in user code. Let me give you a better
example:

struct div_res {int quo, int rem };

struct div_res my_divmod(int a, int b) {
  struct div_res result;
  result.quo = a/b;
  result.rem = a%b;
  return div;
}

If 'b' is zero, my_divmod, when linking with compiler-rt, will return
zero. Now, a "cautious" developer has a great idea! Let me make this
function safer!

struct div_res {int quo, int rem };

struct div_res my_divmod(int a, int b) {
 if (b == 0)
    return __aeabi_idiv0(a);

  struct div_res result;
  result.quo = a/b;
  result.rem = a%b;
  return div;
}

my_divmod will now, return 'a'.

That's not acceptable.

cheers,
--renato



More information about the llvm-dev mailing list