From 5ad5c3c7ed231d9c319cbe91f74f88f8bce59688 Mon Sep 17 00:00:00 2001 From: Sven van Haastregt Date: Fri, 11 May 2018 09:45:42 +0000 Subject: [PATCH] [APFloat] Set losesInfo on no-op convert 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 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/llvm/lib/Support/APFloat.cpp b/llvm/lib/Support/APFloat.cpp index 9035017a9c48..24005c1890c9 100644 --- a/llvm/lib/Support/APFloat.cpp +++ b/llvm/lib/Support/APFloat.cpp @@ -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(getSemantics()) && usesLayout(ToSemantics)) return U.IEEE.convert(ToSemantics, RM, losesInfo);