diff options
author | Pavel Labath <labath@google.com> | 2017-06-23 12:55:02 +0000 |
---|---|---|
committer | Pavel Labath <labath@google.com> | 2017-06-23 12:55:02 +0000 |
commit | ec000f42faa4b139371b0a490a7201c29c22193d (patch) | |
tree | 881a669e79bc5bc115651c2ec634efdf0151b552 /llvm/lib/Support/CommandLine.cpp | |
parent | d5f7711ebb1a6b4df4704693f17a376f76137381 (diff) | |
download | bcm5719-llvm-ec000f42faa4b139371b0a490a7201c29c22193d.tar.gz bcm5719-llvm-ec000f42faa4b139371b0a490a7201c29c22193d.zip |
[ADT] Add llvm::to_float
Summary:
The function matches the interface of llvm::to_integer, but as we are
calling out to a C library function, I let it take a Twine argument, so
we can avoid a string copy at least in some cases.
I add a test and replace a couple of existing uses of strtod with this
function.
Reviewers: zturner
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D34518
llvm-svn: 306096
Diffstat (limited to 'llvm/lib/Support/CommandLine.cpp')
-rw-r--r-- | llvm/lib/Support/CommandLine.cpp | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/llvm/lib/Support/CommandLine.cpp b/llvm/lib/Support/CommandLine.cpp index de0ca940b40..0345a5e3d2a 100644 --- a/llvm/lib/Support/CommandLine.cpp +++ b/llvm/lib/Support/CommandLine.cpp @@ -24,6 +24,7 @@ #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/SmallString.h" +#include "llvm/ADT/StringExtras.h" #include "llvm/ADT/StringMap.h" #include "llvm/ADT/Twine.h" #include "llvm/Config/config.h" @@ -1522,13 +1523,9 @@ bool parser<unsigned long long>::parse(Option &O, StringRef ArgName, // parser<double>/parser<float> implementation // static bool parseDouble(Option &O, StringRef Arg, double &Value) { - SmallString<32> TmpStr(Arg.begin(), Arg.end()); - const char *ArgStart = TmpStr.c_str(); - char *End; - Value = strtod(ArgStart, &End); - if (*End != 0) - return O.error("'" + Arg + "' value invalid for floating point argument!"); - return false; + if (to_float(Arg, Value)) + return false; + return O.error("'" + Arg + "' value invalid for floating point argument!"); } bool parser<double>::parse(Option &O, StringRef ArgName, StringRef Arg, |