[PATCH] D15375: Fix PR #25788: parsing of floating-point constants on non-C locales

Antoine Pitrou via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 9 05:19:09 PST 2015


pitrou created this revision.
pitrou added a subscriber: llvm-commits.

http://reviews.llvm.org/D15375

Files:
  lib/AsmParser/LLLexer.cpp
  unittests/AsmParser/AsmParserTest.cpp

Index: unittests/AsmParser/AsmParserTest.cpp
===================================================================
--- unittests/AsmParser/AsmParserTest.cpp
+++ unittests/AsmParser/AsmParserTest.cpp
@@ -16,6 +16,10 @@
 #include "llvm/Support/SourceMgr.h"
 #include "gtest/gtest.h"
 
+#if !LLVM_ON_WIN32
+#include <locale.h>
+#endif
+
 using namespace llvm;
 
 namespace {
@@ -80,6 +84,19 @@
   ASSERT_TRUE(isa<ConstantFP>(V));
   EXPECT_TRUE(cast<ConstantFP>(V)->isExactlyValue(3.5));
 
+  // https://llvm.org/bugs/show_bug.cgi?id=25788
+#if !LLVM_ON_WIN32
+  char *oldLoc = setlocale(LC_ALL, NULL);
+  if (setlocale(LC_ALL, "fr_FR.UTF-8")) {
+    V = parseConstantValue("double 1.25e+01", Error, M);
+    setlocale(LC_ALL, oldLoc);
+    ASSERT_TRUE(V);
+    EXPECT_TRUE(V->getType()->isDoubleTy());
+    ASSERT_TRUE(isa<ConstantFP>(V));
+    EXPECT_TRUE(cast<ConstantFP>(V)->isExactlyValue(12.5));
+  }
+#endif
+
   V = parseConstantValue("i32 42", Error, M);
   ASSERT_TRUE(V);
   EXPECT_TRUE(V->getType()->isIntegerTy());
Index: lib/AsmParser/LLLexer.cpp
===================================================================
--- lib/AsmParser/LLLexer.cpp
+++ lib/AsmParser/LLLexer.cpp
@@ -937,7 +937,8 @@
     }
   }
 
-  APFloatVal = APFloat(std::atof(TokStart));
+  APFloatVal = APFloat(APFloat::IEEEdouble,
+                       StringRef(TokStart, CurPtr - TokStart));
   return lltok::APFloat;
 }
 
@@ -973,6 +974,7 @@
     }
   }
 
-  APFloatVal = APFloat(std::atof(TokStart));
+  APFloatVal = APFloat(APFloat::IEEEdouble,
+                       StringRef(TokStart, CurPtr - TokStart));
   return lltok::APFloat;
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D15375.42286.patch
Type: text/x-patch
Size: 1624 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151209/31e85e2f/attachment.bin>


More information about the llvm-commits mailing list