[llvm-dev] [compiler-rt] Undefined negation in float emulation functions

Matthew Fernandez via llvm-dev llvm-dev at lists.llvm.org
Tue Oct 20 03:38:06 PDT 2015


Hi,

I recently came across the following in __floatsidf in compiler-rt:

     __floatsidf(int a) {
         ...
         if (a < 0) {
             ...
             a = -a;

In the case where a == INT_MIN, is this negation not undefined behaviour? AIUI this function is used for software 
emulation on targets that have no hardware floating point support. Perhaps there is an in-built assumption that this 
code is never called with INT_MIN, though I don't immediately see anything to indicate this. Indeed there is a later 
comment in this function that indicates INT_MIN is an anticipated input, but the negation has already occurred by this 
point.

I am not a floating point expert, so perhaps I am missing some subtlety here. If so, apologies for the noise. The above 
refers to r218935 and similar code is present in __floatsisf.

Thanks,
Matthew


More information about the llvm-dev mailing list