From c5fb73c5d1b3f1adb77d99fc85c594b48bff08f9 Mon Sep 17 00:00:00 2001 From: Ehud Katz Date: Mon, 6 Jan 2020 10:05:00 +0200 Subject: [APFloat] Add recoverable string parsing errors to APFloat Implementing the APFloat part in PR4745. Differential Revision: https://reviews.llvm.org/D69770 --- llvm/lib/Support/StringRef.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'llvm/lib/Support/StringRef.cpp') 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 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; -- cgit v1.2.3