aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Support/StringRef.cpp
diff options
context:
space:
mode:
authorEhud Katz <ehudkatz@gmail.com>2020-01-09 09:42:32 +0200
committerEhud Katz <ehudkatz@gmail.com>2020-01-09 09:42:32 +0200
commit24b326cc610dfdccdd50bc78505ec228d96c8e7a (patch)
treec3ff8db5608329acfb536b64f40467440145bff0 /llvm/lib/Support/StringRef.cpp
parent4ebb589629b0d3de0827cab179338836ebb3a8b6 (diff)
downloadllvm-24b326cc610dfdccdd50bc78505ec228d96c8e7a.zip
llvm-24b326cc610dfdccdd50bc78505ec228d96c8e7a.tar.gz
llvm-24b326cc610dfdccdd50bc78505ec228d96c8e7a.tar.bz2
[APFloat] Fix checked error assert failures
`APFLoat::convertFromString` returns `Expected` result, which must be "checked" if the LLVM_ENABLE_ABI_BREAKING_CHECKS preprocessor flag is set. To mark an `Expected` result as "checked" we must consume the `Error` within. In many cases, we are only interested in knowing if an error occured, without the need to examine the error info. This is achieved, easily, with the `errorToBool()` API.
Diffstat (limited to 'llvm/lib/Support/StringRef.cpp')
-rw-r--r--llvm/lib/Support/StringRef.cpp8
1 files changed, 3 insertions, 5 deletions
diff --git a/llvm/lib/Support/StringRef.cpp b/llvm/lib/Support/StringRef.cpp
index b5db172..104482d 100644
--- a/llvm/lib/Support/StringRef.cpp
+++ b/llvm/lib/Support/StringRef.cpp
@@ -588,13 +588,11 @@ bool StringRef::getAsInteger(unsigned Radix, APInt &Result) const {
bool StringRef::getAsDouble(double &Result, bool AllowInexact) const {
APFloat F(0.0);
- auto ErrOrStatus = F.convertFromString(*this, APFloat::rmNearestTiesToEven);
- if (!ErrOrStatus) {
- assert(false && "Invalid floating point representation");
+ auto StatusOrErr = F.convertFromString(*this, APFloat::rmNearestTiesToEven);
+ if (errorToBool(StatusOrErr.takeError()))
return true;
- }
- APFloat::opStatus Status = *ErrOrStatus;
+ APFloat::opStatus Status = *StatusOrErr;
if (Status != APFloat::opOK) {
if (!AllowInexact || !(Status & APFloat::opInexact))
return true;