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

Renato Golin renato.golin at linaro.org
Thu Sep 11 13:37:34 PDT 2014


After a chat with Saleem, I agree that the usage in this case is ok,
since the div0 is *meant* to be implemented if any consistent
behaviour is expected, otherwise, here be dragons. Also, in its lowest
form, div0 should be just a return, which in the case of ARM, leaves
R0 intact, so returning the argument makes a lot of sense.

Ignore my musings, all is well.

cheers,
--renato

On 10 September 2014 10:40, Renato Golin <renato.golin at linaro.org> wrote:
> 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