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

Chris Lattner via llvm-dev llvm-dev at lists.llvm.org
Sat Oct 24 15:02:01 PDT 2015


> On Oct 23, 2015, at 7:43 PM, Matthew Fernandez via llvm-dev <llvm-dev at lists.llvm.org> wrote:
> On 21/10/15 00:15, Stephen Canon wrote:
>> Yup, this is UB.  If you want to propose a patch, I would do something like the following:
>> 
>> 	rep_t sign = 0;
>> 	unsigned int aAbs = a;
>> 	if (a < 0) {
>> 		sign = signBit;
>> 		aAbs = -aAbs;
>> 	}
>> 	// Now use aAbs instead of a.

FWIW, another way to avoid the UB is to use an unsigned value.

-Chris


More information about the llvm-dev mailing list