[LLVMbugs] [Bug 12906] New: AsmWriter produces invalid IR when using certain locales (comma ', ' instead of periods '.')

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Mon May 21 13:58:44 PDT 2012


             Bug #: 12906
           Summary: AsmWriter produces invalid IR when using certain
                    locales (comma ',' instead of periods '.')
           Product: libraries
           Version: trunk
          Platform: All
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Core LLVM classes
        AssignedTo: unassignedbugs at nondot.org
        ReportedBy: empann at hotmail.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

Hi. I have my LANG environment variable set to LANG=sv_SE.UTF-8 since I live in
Sweden. In my program I also use setlocale(LC_ALL, "") before using LLVM

If I know write printf("%e\n", 1.8); I get 1,800000e+00.
If I omit the setlocale(LC_ALL, ""); I get 1.800000e+00 instead.

LLVM uses snprintf to print out doubles in AsmWriter, which (of course)
produces strings with comma instead of period, when locale settings are set as
they are above. That is incorrect, since LLVM only allows doubles with periods
and not commas.
I even get the assertion:

/home/ubuntu/llvm/lib/Support/APFloat.cpp:285: void
interpretDecimal(llvm::StringRef::iterator, llvm::StringRef::iterator,
decimalInfo*): Assertion `(*p == 'e' || *p == 'E') && "Invalid character in
significand"' failed.
Aborted (core dumped)

Stack backtrace:
#4  0xb64a9147 in __GI___assert_fail (
    assertion=0xb7c01690 "(*p == 'e' || *p == 'E') && \"Invalid character in
    file=0xb7c01264 "/home/ubuntu/llvm/lib/Support/APFloat.cpp", line=285, 
    function=0xb7c029a0 "void interpretDecimal(llvm::StringRef::iterator,
llvm::StringRef::iterator, decimalInfo*)") at assert.c:103
#5  0xb75b108f in llvm::APFloat::convertFromDecimalString(llvm::StringRef,
llvm::APFloat::roundingMode) ()
   from /usr/lib/libLLVM-3.2svn.so
#6  0xb75b1227 in llvm::APFloat::convertFromString(llvm::StringRef,
llvm::APFloat::roundingMode) ()
   from /usr/lib/libLLVM-3.2svn.so
#7  0xb75b1371 in llvm::APFloat::APFloat(llvm::fltSemantics const&,
llvm::StringRef) ()
   from /usr/lib/libLLVM-3.2svn.so
#8  0xb6ed1df0 in WriteConstantInternal(llvm::raw_ostream&, llvm::Constant
const*, (anonymous namespace)::TypePrinting&, (anonymous
namespace)::SlotTracker*, llvm::Module const*) () from
#9  0xb6ecd00f in (anonymous
namespace)::AssemblyWriter::writeOperand(llvm::Value const*, bool) ()
   from /usr/lib/libLLVM-3.2svn.so
#10 0xb6ecdcde in (anonymous
namespace)::AssemblyWriter::printInstruction(llvm::Instruction const&) ()
   from /usr/lib/libLLVM-3.2svn.so
#11 0xb6ecf729 in (anonymous
namespace)::AssemblyWriter::printBasicBlock(llvm::BasicBlock const*) ()
   from /usr/lib/libLLVM-3.2svn.so
#12 0xb6ecfee1 in (anonymous
namespace)::AssemblyWriter::printFunction(llvm::Function const*) ()
   from /usr/lib/libLLVM-3.2svn.so
#13 0xb6ed0c11 in llvm::Module::print(llvm::raw_ostream&,
llvm::AssemblyAnnotationWriter*) const ()
---Type <return> to continue, or q <return> to quit---
   from /usr/lib/libLLVM-3.2svn.so
#14 0x0804a25f in llvm::operator<<(llvm::raw_ostream&, llvm::Module const&) ()
#15 0x08049a5d in main ()

This comes from the example HowToUseJIT, by adding setlocale(LC_ALL, ""); as
the first line in main(), and having LANG environment variable set as
sv_SE.UTF-8 with Ubuntu 12.04.

It is WriteConstantInternal in AsmWriter.cpp that uses
SmallString<128> StrVal;
raw_svector_ostream(StrVal) << Val;
to write a double.

Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.

More information about the llvm-bugs mailing list