]> granicus.if.org Git - llvm/commit
[AsmWriter/APFloat] FP constant printing: Avoid usage of locale dependent snprinf
authorSerguei Katkov <serguei.katkov@azul.com>
Fri, 21 Apr 2017 02:52:17 +0000 (02:52 +0000)
committerSerguei Katkov <serguei.katkov@azul.com>
Fri, 21 Apr 2017 02:52:17 +0000 (02:52 +0000)
commitc849a0cc07bf2e2cd1e1b193a8644ff7907c02f0
tree50b151701dcd2e981858d586a9cec3ae06f13144
parent1933132d0a4fced0fde49266fc9195b601d4170d
[AsmWriter/APFloat] FP constant printing: Avoid usage of locale dependent snprinf

This should fix the bug https://bugs.llvm.org/show_bug.cgi?id=12906

To print the FP constant AsmWriter does the following:

  1) convert FP value to String (actually using snprintf function which is locale dependent).
  2) Convert String back to FP Value
  3) Compare original and got FP values. If they are not equal just dump as hex.

The problem happens on the 2nd step when APFloat does not expect group delimiter or
fraction delimiter other than period symbol and so on, which can be produced on the
first step if LLVM library is used in an environment with corresponding locale set.

To fix this issue the locale independent APFloat:toString function is used.
However it prints FP values slightly differently than snprintf does. Specifically
it suppress trailing zeros in significant, use capital E and so on.
It results in 117 test failures during make check.
To avoid this I've also updated APFloat.toString a bit to pass make check at least.

Reviewers: sberg, bogner, majnemer, sanjoy, timshen, rnk

Reviewed By: timshen, rnk

Subscribers: rnk, llvm-commits

Differential Revision: https://reviews.llvm.org/D32276

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@300943 91177308-0d34-0410-b5e6-96231b3b80d8
include/llvm/ADT/APFloat.h
lib/IR/AsmWriter.cpp
lib/Support/APFloat.cpp
unittests/ADT/APFloatTest.cpp