diff options
author | Alexey Samsonov <samsonov@google.com> | 2012-11-30 22:27:54 +0000 |
---|---|---|
committer | Alexey Samsonov <samsonov@google.com> | 2012-11-30 22:27:54 +0000 |
commit | 2b431d97aa7f702acb919e432fac39da1a27ccfb (patch) | |
tree | b56896ce2d79c5f5c016584b1e350d77a79b0b4e /llvm/lib/Support | |
parent | d2901e94f1734bc5498a37eae59591cd7e499dd7 (diff) | |
download | bcm5719-llvm-2b431d97aa7f702acb919e432fac39da1a27ccfb.tar.gz bcm5719-llvm-2b431d97aa7f702acb919e432fac39da1a27ccfb.zip |
Fix a bug in APFloat.cpp: declare APFloat after fltSemantics it
uses. APFloat::convert() takes the pointer to the fltSemantics
variable, which is later accessed it in ~APFloat() desctructor.
That is, semantics must still be alive at the moment we delete
APFloat.
Found by experimental AddressSanitizer use-after-scope checker.
llvm-svn: 169047
Diffstat (limited to 'llvm/lib/Support')
-rw-r--r-- | llvm/lib/Support/APFloat.cpp | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/llvm/lib/Support/APFloat.cpp b/llvm/lib/Support/APFloat.cpp index 7e8b4a3d0d2..1658d961fb5 100644 --- a/llvm/lib/Support/APFloat.cpp +++ b/llvm/lib/Support/APFloat.cpp @@ -2761,9 +2761,11 @@ APFloat::convertPPCDoubleDoubleAPFloatToAPInt() const // normalize against the "double" minExponent first, and only *then* // truncate the mantissa. The result of that second conversion // may be inexact, but should never underflow. - APFloat extended(*this); + // Declare fltSemantics before APFloat that uses it (and + // saves pointer to it) to ensure correct destruction order. fltSemantics extendedSemantics = *semantics; extendedSemantics.minExponent = IEEEdouble.minExponent; + APFloat extended(*this); fs = extended.convert(extendedSemantics, rmNearestTiesToEven, &losesInfo); assert(fs == opOK && !losesInfo); (void)fs; |