diff options
author | Ehud Katz <ehudkatz@gmail.com> | 2020-01-06 10:05:00 +0200 |
---|---|---|
committer | Ehud Katz <ehudkatz@gmail.com> | 2020-01-06 10:09:01 +0200 |
commit | c5fb73c5d1b3f1adb77d99fc85c594b48bff08f9 (patch) | |
tree | 89df48258530ece7f2d2f32a3c5d31bc433013b1 /llvm/lib/Support/StringRef.cpp | |
parent | a7929533300535547f8484f7e38765234a7e7c93 (diff) | |
download | bcm5719-llvm-c5fb73c5d1b3f1adb77d99fc85c594b48bff08f9.tar.gz bcm5719-llvm-c5fb73c5d1b3f1adb77d99fc85c594b48bff08f9.zip |
[APFloat] Add recoverable string parsing errors to APFloat
Implementing the APFloat part in PR4745.
Differential Revision: https://reviews.llvm.org/D69770
Diffstat (limited to 'llvm/lib/Support/StringRef.cpp')
-rw-r--r-- | llvm/lib/Support/StringRef.cpp | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/llvm/lib/Support/StringRef.cpp b/llvm/lib/Support/StringRef.cpp index 393504cf01b..4142d130d51 100644 --- a/llvm/lib/Support/StringRef.cpp +++ b/llvm/lib/Support/StringRef.cpp @@ -12,6 +12,7 @@ #include "llvm/ADT/Hashing.h" #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/edit_distance.h" +#include "llvm/Support/Error.h" #include <bitset> using namespace llvm; @@ -587,8 +588,13 @@ bool StringRef::getAsInteger(unsigned Radix, APInt &Result) const { bool StringRef::getAsDouble(double &Result, bool AllowInexact) const { APFloat F(0.0); - APFloat::opStatus Status = - F.convertFromString(*this, APFloat::rmNearestTiesToEven); + auto ErrOrStatus = F.convertFromString(*this, APFloat::rmNearestTiesToEven); + if (!ErrOrStatus) { + assert("Invalid floating point representation"); + return true; + } + + APFloat::opStatus Status = *ErrOrStatus; if (Status != APFloat::opOK) { if (!AllowInexact || !(Status & APFloat::opInexact)) return true; |