Steve Canon via llvm-dev
2015-Oct-25 10:46 UTC
[llvm-dev] [compiler-rt] Undefined negation in float emulation functions
On Oct 24, 2015, at 6:02 PM, Chris Lattner <clattner at apple.com> wrote:> > >> 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.I'm confused, that's exactly what this does. - Steve
Joerg Sonnenberger via llvm-dev
2015-Oct-25 15:54 UTC
[llvm-dev] [compiler-rt] Undefined negation in float emulation functions
On Sun, Oct 25, 2015 at 06:46:48AM -0400, Steve Canon via llvm-dev wrote:> On Oct 24, 2015, at 6:02 PM, Chris Lattner <clattner at apple.com> wrote: > > > > > >> 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. > > I'm confused, that's exactly what this does.At least in one place it is negating the signed variable, not creating a new unsigned variable. Joerg
Matthew Fernandez via llvm-dev
2015-Oct-25 20:56 UTC
[llvm-dev] [compiler-rt] Undefined negation in float emulation functions
On 26/10/15 02:54, Joerg Sonnenberger wrote:> On Sun, Oct 25, 2015 at 06:46:48AM -0400, Steve Canon via llvm-dev wrote: >> On Oct 24, 2015, at 6:02 PM, Chris Lattner <clattner at apple.com> wrote: >>> >>> >>>> 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. >> >> I'm confused, that's exactly what this does. > > At least in one place it is negating the signed variable, not creating a > new unsigned variable.Chris, were you suggesting a cast (`a = -(unsigned)a`)? Otherwise, like Steve, I don't understand the difference between this proposal and Steve's code above.
Possibly Parallel Threads
- [compiler-rt] Undefined negation in float emulation functions
- [compiler-rt] Undefined negation in float emulation functions
- [compiler-rt] Undefined negation in float emulation functions
- libc++ failed to link against musl
- [LLVMdev] Issues in compiler-rt __truncdfsf2 and __extendsfdf2 functions?