[APFloat] Set losesInfo on no-op convert
authorSven van Haastregt <sven.vanhaastregt@arm.com>
Fri, 11 May 2018 09:45:42 +0000 (09:45 +0000)
committerSven van Haastregt <sven.vanhaastregt@arm.com>
Fri, 11 May 2018 09:45:42 +0000 (09:45 +0000)
losesInfo would be left unset when no conversion needs to be done.  A
caller such as InstCombine's fitsInFPType would then branch on an
uninitialized value.

Caught using valgrind on an out-of-tree target.

Differential Revision: https://reviews.llvm.org/D46645

llvm-svn: 332087

llvm/lib/Support/APFloat.cpp

index 9035017..24005c1 100644 (file)
@@ -4443,8 +4443,10 @@ APFloat::APFloat(const fltSemantics &Semantics, StringRef S)
 
 APFloat::opStatus APFloat::convert(const fltSemantics &ToSemantics,
                                    roundingMode RM, bool *losesInfo) {
-  if (&getSemantics() == &ToSemantics)
+  if (&getSemantics() == &ToSemantics) {
+    *losesInfo = false;
     return opOK;
+  }
   if (usesLayout<IEEEFloat>(getSemantics()) &&
       usesLayout<IEEEFloat>(ToSemantics))
     return U.IEEE.convert(ToSemantics, RM, losesInfo);